Skip to content

Commit

Permalink
Merge branch 'VID-686' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dthies committed Aug 4, 2023
2 parents 69ab649 + 55dc52b commit 269aef8
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
17 changes: 17 additions & 0 deletions plugin/videojs/classes/video_embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@

namespace videotimeplugin_videojs;

use context_module;
use core_component;
use mod_videotime\vimeo_embed;
use moodle_url;
use renderer_base;

defined('MOODLE_INTERNAL') || die();
Expand Down Expand Up @@ -55,9 +57,24 @@ public function export_for_template(renderer_base $output) {

$mimetype = resourcelib_guess_url_mimetype($this->record->vimeo_url);

$context = context_module::instance($this->get_cm()->id);
$fs = get_file_storage();
foreach ($fs->get_area_files($context->id, 'videotimeplugin_videojs', 'poster') as $file) {
if (!$file->is_directory()) {
$poster = moodle_url::make_pluginfile_url(
$context->id,
'videotimeplugin_videojs',
'poster',
0,
$file->get_filepath(),
$file->get_filename()
)->out(false);
}
}
$context = parent::export_for_template($output) + [
'mimetype' => $mimetype,
'video' => !file_mimetype_in_typegroup($mimetype, ['web_audio']),
'poster' => $poster ?? false,
];

return $context;
Expand Down
2 changes: 2 additions & 0 deletions plugin/videojs/lang/en/videotimeplugin_videojs.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@
$string['mediafile'] = 'Media file';
$string['mediafile_help'] = 'Upload an audio or video file to use';
$string['pluginname'] = 'Video Time VideoJS Player';
$string['poster'] = 'Poster file';
$string['poster_help'] = 'Upload a poster image that will be displayed before video is started';
$string['privacy:metadata'] = 'The Video Time VideoJS Player plugin does not store any personal data.';
40 changes: 38 additions & 2 deletions plugin/videojs/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ function videotimeplugin_videojs_update_instance($moduleinstance, $mform = null)
0,
['subdirs' => 0, 'maxfiles' => 1]
);

file_save_draft_area_files(
$data->poster,
$context->id,
'videotimeplugin_videojs',
'poster',
0,
['subdirs' => 0, 'maxfiles' => 1]
);
}
}

Expand Down Expand Up @@ -225,6 +234,23 @@ function videotimeplugin_videojs_add_form_fields($mform, $formclass) {
'name'
);
$mform->addHelpButton('mediafile', 'mediafile', 'videotimeplugin_videojs');

$mform->insertElementBefore(
$mform->createElement('filemanager', 'poster', get_string('poster', 'videotimeplugin_videojs'), null, [
'subdirs' => 0,
'maxfiles' => 1,
'accepted_types' => ['image'],
]),
'name'
);
$mform->addHelpButton('poster', 'poster', 'videotimeplugin_videojs');
} else {
$mform->addElement('filemanager', 'poster', get_string('poster', 'videotimeplugin_videojs'), null, [
'subdirs' => 0,
'maxfiles' => 1,
'accepted_types' => ['image'],
]);
$mform->addHelpButton('poster', 'poster', 'videotimeplugin_videojs');
}
}

Expand All @@ -248,7 +274,14 @@ function videotimeplugin_videojs_data_preprocessing(array &$defaultvalues, int $
'mediafile',
0
);
$defaultvalues['mediafile'] = $draftitemid;
file_prepare_draft_area(
$draftitemid,
$context->id,
'videotimeplugin_videojs',
'poster',
0
);
$defaultvalues['poster'] = $draftitemid;
}
}

Expand All @@ -272,7 +305,9 @@ function videotimeplugin_videojs_pluginfile($course, $cm, $context, $filearea, $

require_login($course, true, $cm);

if ($filearea == 'mediafile') {
if (in_array($filearea, [
'mediafile', 'poster',
])) {

$relativepath = implode('/', $args);

Expand All @@ -295,5 +330,6 @@ function videotimeplugin_videojs_pluginfile($course, $cm, $context, $filearea, $
function videotimeplugin_videojs_config_file_areas() {
return [
'mediafile',
'poster',
];
}
1 change: 1 addition & 0 deletions plugin/videojs/templates/video_embed.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
{{# video }}
<video class="video-js"
id="vimeo-embed-{{uniqueid}}"
{{# poster }} poster="{{ poster }}" {{/ poster }}
controls {{# playsinline }} playsinline {{/ playsinline }}
>
</video>
Expand Down

0 comments on commit 269aef8

Please sign in to comment.