'name' => 'videoFiles',
'title' => 'Видео: mp4, mov, avi',
'type' => FileInput::class,
- 'value' => function ($row) {
- if (!isset($row['id'])) return null;
-
- $file = Files::findOne([
- 'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO,
- 'entity_id' => $row['id'],
- ]);
-
- return $file ? $file->url : null;
- },
- 'columnOptions' => function ($rowModel, $index, $context) {
- $file = null;
- $initialPreviewConfig = [];
-
- if (isset($rowModel['id'])) {
- $file = Files::findOne([
- 'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO,
- 'entity_id' => $rowModel['id'],
- ]);
-
- if ($file) {
- $initialPreviewConfig = [[
- 'caption' => basename($file->url),
- 'url' => \yii\helpers\Url::to(['delete-video', 'id' => $rowModel['id']]),
- ]];
- }
- }
-
- return [
- 'attribute' => 'videoFiles',
- 'options' => [
- 'multiple' => false,
- 'accept' => 'video/*',
- 'name' => 'video_name',
- 'class' => 'file',
- ],
- 'pluginOptions' => [
- 'showPreview' => false, // отключаем превью видео
- 'showCaption' => true, // показываем название файла
- 'showRemove' => true,
- 'showUpload' => true,
- 'initialPreview' => [], // без превью
- 'initialPreviewAsData' => false, // без превью как данные
- 'initialPreviewConfig' => $initialPreviewConfig,
- 'browseLabel' => '+',
- 'removeLabel' => '-',
- 'cancelLabel' => 'x',
- 'layoutTemplates' => [
- 'actions' => '<div class="file-actions">{remove} {upload} {cancel}</div>',
- 'actionUpload' => '<button type="button" title="{uploadTitle}" class="kv-file-upload {uploadClass}" style="margin-left:5px">{uploadIcon}</button>',
- 'actionRemove' => '<button type="button" title="{removeTitle}" class="kv-file-remove {removeClass}">{removeIcon}</button>',
- 'actionCancel' => '<button type="button" title="{cancelTitle}" class="kv-file-cancel {cancelClass}">{cancelIcon}</button>',
- ],
- 'fileActionSettings' => [
- 'showUpload' => true,
- 'showRemove' => true,
- 'showZoom' => false,
- 'showDrag' => false,
- ],
- ],
- ];
- },
+ 'options' => [
+ 'options' => [
+ 'multiple' => false,
+ 'accept' => 'video/*',
+ 'name' => 'video_name',
+ ],
+ 'pluginOptions' => [
+ 'showPreview' => true,
+ 'showCaption' => true,
+ 'showRemove' => true,
+ 'showUpload' => false,
+ 'previewFileType' => 'video',
+ 'allowedFileExtensions' => ['mp4', 'mov', 'avi'],
+ 'initialPreview' => isset($model->id) ? [ // или $row['id'], если это в цикле
+ Files::find()
+ ->select('url')
+ ->where([
+ 'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO,
+ 'entity_id' => $model->id // или $row['id']
+ ])
+ ->scalar()
+ ] : [],
+ 'initialPreviewAsData' => true,
+ 'initialPreviewConfig' => isset($model->id) ? [[
+ 'type' => 'video',
+ 'caption' => basename(
+ Files::find()
+ ->select('url')
+ ->where([
+ 'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO,
+ 'entity_id' => $model->id
+ ])
+ ->scalar()
+ ),
+ 'url' => Url::to(['delete-video', 'id' => $model->id]),
+ ]] : [],
+ ]
+ ]
],
[
'name' => 'comment',