From bdf99377e1b5a2771e971e4ac17bb8ba971971da Mon Sep 17 00:00:00 2001 From: Eli Zoller <5439169+elizoller@users.noreply.github.com> Date: Wed, 17 Mar 2021 19:57:16 -0700 Subject: [PATCH] captions v2 (#826) --- .../islandora_audio/islandora_audio.module | 15 ++ .../IslandoraFileAudioFormatter.php | 28 +++ .../templates/islandora-file-audio.html.twig | 28 +++ .../islandora_video/islandora_video.module | 15 ++ .../IslandoraFileVideoFormatter.php | 95 ++++++++ .../templates/islandora-file-video.html.twig | 27 +++ .../IslandoraFileMediaFormatterBase.php | 92 +++++++ src/Plugin/Field/FieldType/MediaTrackItem.php | 224 ++++++++++++++++++ .../Field/FieldWidget/MediaTrackWidget.php | 173 ++++++++++++++ 9 files changed, 697 insertions(+) create mode 100644 modules/islandora_audio/src/Plugin/Field/FieldFormatter/IslandoraFileAudioFormatter.php create mode 100644 modules/islandora_audio/templates/islandora-file-audio.html.twig create mode 100644 modules/islandora_video/src/Plugin/Field/FieldFormatter/IslandoraFileVideoFormatter.php create mode 100644 modules/islandora_video/templates/islandora-file-video.html.twig create mode 100644 src/Plugin/Field/FieldFormatter/IslandoraFileMediaFormatterBase.php create mode 100644 src/Plugin/Field/FieldType/MediaTrackItem.php create mode 100644 src/Plugin/Field/FieldWidget/MediaTrackWidget.php diff --git a/modules/islandora_audio/islandora_audio.module b/modules/islandora_audio/islandora_audio.module index a5093c1b..07b93840 100644 --- a/modules/islandora_audio/islandora_audio.module +++ b/modules/islandora_audio/islandora_audio.module @@ -30,3 +30,18 @@ function islandora_audio_help($route_name, RouteMatchInterface $route_match) { default: } } + +/** + * Implements hook_theme(). + */ +function islandora_audio_theme() { + return [ + 'islandora_file_audio' => [ + 'variables' => [ + 'files' => [], + 'tracks' => NULL, + 'attributes' => NULL, + ], + ], + ]; +} diff --git a/modules/islandora_audio/src/Plugin/Field/FieldFormatter/IslandoraFileAudioFormatter.php b/modules/islandora_audio/src/Plugin/Field/FieldFormatter/IslandoraFileAudioFormatter.php new file mode 100644 index 00000000..579da554 --- /dev/null +++ b/modules/islandora_audio/src/Plugin/Field/FieldFormatter/IslandoraFileAudioFormatter.php @@ -0,0 +1,28 @@ + + {% for file in files %} + + {% if tracks %} + {% for track in tracks %} + + diff --git a/modules/islandora_video/islandora_video.module b/modules/islandora_video/islandora_video.module index d45baf06..a1ef752b 100644 --- a/modules/islandora_video/islandora_video.module +++ b/modules/islandora_video/islandora_video.module @@ -30,3 +30,18 @@ function islandora_video_help($route_name, RouteMatchInterface $route_match) { default: } } + +/** + * Implements hook_theme(). + */ +function islandora_video_theme() { + return [ + 'islandora_file_video' => [ + 'variables' => [ + 'files' => [], + 'tracks' => NULL, + 'attributes' => NULL, + ], + ], + ]; +} diff --git a/modules/islandora_video/src/Plugin/Field/FieldFormatter/IslandoraFileVideoFormatter.php b/modules/islandora_video/src/Plugin/Field/FieldFormatter/IslandoraFileVideoFormatter.php new file mode 100644 index 00000000..47fca594 --- /dev/null +++ b/modules/islandora_video/src/Plugin/Field/FieldFormatter/IslandoraFileVideoFormatter.php @@ -0,0 +1,95 @@ + FALSE, + 'width' => 640, + 'height' => 480, + ] + parent::defaultSettings(); + } + + /** + * {@inheritdoc} + */ + public function settingsForm(array $form, FormStateInterface $form_state) { + return parent::settingsForm($form, $form_state) + [ + 'muted' => [ + '#title' => $this->t('Muted'), + '#type' => 'checkbox', + '#default_value' => $this->getSetting('muted'), + ], + 'width' => [ + '#type' => 'number', + '#title' => $this->t('Width'), + '#default_value' => $this->getSetting('width'), + '#size' => 5, + '#maxlength' => 5, + '#field_suffix' => $this->t('pixels'), + '#min' => 0, + '#required' => TRUE, + ], + 'height' => [ + '#type' => 'number', + '#title' => $this->t('Height'), + '#default_value' => $this->getSetting('height'), + '#size' => 5, + '#maxlength' => 5, + '#field_suffix' => $this->t('pixels'), + '#min' => 0, + '#required' => TRUE, + ], + ]; + } + + /** + * {@inheritdoc} + */ + public function settingsSummary() { + $summary = parent::settingsSummary(); + $summary[] = $this->t('Muted: %muted', ['%muted' => $this->getSetting('muted') ? $this->t('yes') : $this->t('no')]); + $summary[] = $this->t('Size: %width x %height pixels', [ + '%width' => $this->getSetting('width'), + '%height' => $this->getSetting('height'), + ]); + return $summary; + } + + /** + * {@inheritdoc} + */ + protected function prepareAttributes(array $additional_attributes = []) { + return parent::prepareAttributes(['muted']) + ->setAttribute('width', $this->getSetting('width')) + ->setAttribute('height', $this->getSetting('height')); + } + +} diff --git a/modules/islandora_video/templates/islandora-file-video.html.twig b/modules/islandora_video/templates/islandora-file-video.html.twig new file mode 100644 index 00000000..7c62bade --- /dev/null +++ b/modules/islandora_video/templates/islandora-file-video.html.twig @@ -0,0 +1,27 @@ +{# +/** +* @file +* Default theme implementation to display the file entity as a video tag. +* +* Available variables: +* - attributes: An array of HTML attributes, intended to be added to the +* video tag. +* - files: And array of files to be added as sources for the video tag. Each +* element is an array with the following elements: +* - file: The full file object. +* - source_attributes: An array of HTML attributes for to be added to the +* source tag. +* +* @ingroup themeable +*/ +#} +