'name' => 'videoFiles',
'title' => 'Видео: mp4, mov, avi',
'type' => FileInput::className(),
- 'value' => function ($model) {
+ 'options' => function ($row, $index) use ($model) {
+ $videoUrl = null;
+
+ if (!empty($model->id)) {
+ $videoUrl = Files::find()
+ ->select('url')
+ ->where([
+ 'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO,
+ 'entity_id' => $model->id
+ ])
+ ->scalar();
+ }
- var_dump($model['id']);
- die();
- },
- 'options' => [
- 'options' => [
- 'multiple' => false,
- 'accept' => 'video/*',
- 'name' => 'video_name',
- 'capture' => '',
- 'class' => 'videos'
- ],
- 'pluginOptions' => [
- 'showPreview' => false,
- 'showCaption' => true,
- 'showRemove' => true,
- 'showUpload' => false,
- 'overwriteInitial' => true,
- 'browseIcon' => '+',
- 'cancelIcon' => 'x',
- 'removeIcon' => '-',
- 'buttonLabelClass' => 'hidden',
- 'fileActionSettings' => ['showUpload' => false],
- 'multiple' => false,
- 'previewFileType' => 'video',
- 'allowedFileExtensions' => ['mp4', 'mov', 'avi'],
- 'initialPreview' => isset($model->id) ? [
- Files::find()
- ->select('url')
- ->where([
- 'entity' => WriteOffsProductsErp::WRITE_OFFS_VIDEO,
- 'entity_id' => $model->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]),
- ]] : [],
- ]
- ]
+ return [
+ 'options' => [
+ 'multiple' => false,
+ 'accept' => 'video/*',
+ 'name' => 'video_name',
+ 'capture' => '',
+ 'class' => 'videos'
+ ],
+ 'pluginOptions' => [
+ 'showPreview' => false,
+ 'showCaption' => true,
+ 'showRemove' => true,
+ 'showUpload' => false,
+ 'overwriteInitial' => true,
+ 'browseIcon' => '+',
+ 'cancelIcon' => 'x',
+ 'removeIcon' => '-',
+ 'buttonLabelClass' => 'hidden',
+ 'fileActionSettings' => ['showUpload' => false],
+ 'multiple' => false,
+ 'previewFileType' => 'video',
+ 'allowedFileExtensions' => ['mp4', 'mov', 'avi'],
+ 'initialPreview' => $videoUrl ? [$videoUrl] : [],
+ 'initialPreviewAsData' => true,
+ 'initialPreviewConfig' => $videoUrl ? [[
+ 'type' => 'video',
+ 'caption' => basename($videoUrl),
+ 'url' => Url::to(['delete-video', 'id' => $model->id]),
+ ]] : [],
+ ]
+ ];
+ }
],
[
'name' => 'comment',