Browse Source

phpcs gets me bad on this one

pull/826/head
elizoller 5 years ago
parent
commit
4cc3455bbd
  1. 5
      modules/islandora_audio/islandora_audio.module
  2. 1
      modules/islandora_audio/src/Plugin/Field/FieldFormatter/IslandoraFileAudioFormatter.php
  3. 3
      modules/islandora_video/islandora_video.module
  4. 1
      modules/islandora_video/src/Plugin/Field/FieldFormatter/IslandoraFileVideoFormatter.php
  5. 17
      src/Plugin/Field/FieldFormatter/IslandoraFileMediaFormatterBase.php
  6. 24
      src/Plugin/Field/FieldType/MediaTrackItem.php
  7. 74
      src/Plugin/Field/FieldWidget/MediaTrackWidget.php

5
modules/islandora_audio/islandora_audio.module

@ -33,7 +33,6 @@ function islandora_audio_help($route_name, RouteMatchInterface $route_match) {
/**
* Implements hook_theme().
*
*/
function islandora_audio_theme() {
return [
@ -41,8 +40,8 @@ function islandora_audio_theme() {
'variables' => [
'files' => [],
'tracks' => NULL,
'attributes' => NULL
'attributes' => NULL,
],
]
],
];
}

1
modules/islandora_audio/src/Plugin/Field/FieldFormatter/IslandoraFileAudioFormatter.php

@ -1,6 +1,7 @@
<?php
namespace Drupal\islandora_audio\Plugin\Field\FieldFormatter;
use Drupal\islandora\Plugin\Field\FieldFormatter\IslandoraFileMediaFormatterBase;
/**

3
modules/islandora_video/islandora_video.module

@ -33,7 +33,6 @@ function islandora_video_help($route_name, RouteMatchInterface $route_match) {
/**
* Implements hook_theme().
*
*/
function islandora_video_theme() {
return [
@ -41,7 +40,7 @@ function islandora_video_theme() {
'variables' => [
'files' => [],
'tracks' => NULL,
'attributes' => NULL
'attributes' => NULL,
],
],
];

1
modules/islandora_video/src/Plugin/Field/FieldFormatter/IslandoraFileVideoFormatter.php

@ -5,7 +5,6 @@ namespace Drupal\islandora_video\Plugin\Field\FieldFormatter;
use Drupal\Core\Form\FormStateInterface;
use Drupal\islandora\Plugin\Field\FieldFormatter\IslandoraFileMediaFormatterBase;
/**
* Plugin implementation of the 'file_video' formatter.
*

17
src/Plugin/Field/FieldFormatter/IslandoraFileMediaFormatterBase.php

@ -8,7 +8,11 @@ use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Template\Attribute;
/**
* Extension of FileMediaFormatterBase that enables captions.
*/
abstract class IslandoraFileMediaFormatterBase extends FileMediaFormatterBase {
/**
* {@inheritdoc}
*/
@ -39,11 +43,13 @@ abstract class IslandoraFileMediaFormatterBase extends FileMediaFormatterBase {
return $elements;
}
/**
/**
* Gets the track files with attributes.
*
* @param \Drupal\Core\Field\EntityReferenceFieldItemListInterface $items
* @param $langcode
* The items.
* @param string $langcode
* The langcode.
*
* @return array
* Numerically indexed array, which again contains an associative array with
@ -55,14 +61,14 @@ abstract class IslandoraFileMediaFormatterBase extends FileMediaFormatterBase {
$track_files = [];
$media_entity = $items->getParent()->getEntity();
$fields = $media_entity->getFields();
foreach ($fields AS $key => $field) {
foreach ($fields as $key => $field) {
$definition = $field->getFieldDefinition();
if (method_exists($definition, 'get')) {
if ($definition->get('field_type') == 'media_track') {
// extract the info for each track
// Extract the info for each track.
$entities = $field->referencedEntities();
$values = $field->getValue();
foreach ($entities AS $delta => $file) {
foreach ($entities as $delta => $file) {
$track_attributes = new Attribute();
$track_attributes
->setAttribute('src', $file->createFileUrl())
@ -83,5 +89,4 @@ abstract class IslandoraFileMediaFormatterBase extends FileMediaFormatterBase {
return $track_files;
}
}

24
src/Plugin/Field/FieldType/MediaTrackItem.php

@ -9,7 +9,6 @@ use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\file\Plugin\Field\FieldType\FileItem;
/**
* Plugin implementation of the 'media_track' field type.
*
@ -188,33 +187,28 @@ class MediaTrackItem extends FileItem {
// @todo This will need to generate a text file, containing a sequence of
// timestamps and nonsense text. Include some gap periods where nothing is
// displayed.
// See the ImageItem::generateSampleValue() for how the files are saved.
// The part about "Generate a max of 5 different images" is a good idea
// here too. We only need a WebVTT few files.
// See one of the text item implementation for how to generate nonsense text.
// See one of the text item implementation for how to generate nonsense.
// Pseudocode plan...
// $sample_file_text = 'WEBVTT'; // start of file.
// for ($i = 0; $ < $utterances; $i++) {
// $sample_file_text += \n\n
// $timestamp += 3-10seconds // start of display
// $sample_file_text += $timestamp
// $timestamp += 3-10seconds // end of display
// $sample_file_text += $timestamp
// $sample_file_text += randomText()
// $sample_file_text += \n\n
// $timestamp += 3-10seconds // start of display
// $sample_file_text += $timestamp
// $timestamp += 3-10seconds // end of display
// $sample_file_text += $timestamp
// $sample_file_text += randomText()
// }
// $file = file_write($sample_file_text, 'random_filename.vtt');
$values = [
'target_id' => $file->id(),
// randomize the rest of these...
// Randomize the rest of these...
'label' => '',
'kind' => '',
'srclang' => '',
// careful with this one, complex validation.
// Careful with this one, complex validation.
'default' => '',
];
return $values;

74
src/Plugin/Field/FieldWidget/MediaTrackWidget.php

@ -2,14 +2,11 @@
namespace Drupal\islandora\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Render\ElementInfoManagerInterface;
use Drupal\file\Plugin\Field\FieldWidget\FileWidget;
/**
* Plugin implementation of the 'media_track' widget.
*
@ -23,39 +20,17 @@ use Drupal\file\Plugin\Field\FieldWidget\FileWidget;
*/
class MediaTrackWidget extends FileWidget {
/**
* Constructs a MediaTrackWidget object.
*
* @param string $plugin_id
* The plugin_id for the widget.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
* The definition of the field to which the widget is associated.
* @param array $settings
* The widget settings.
* @param array $third_party_settings
* Any third party settings.
* @param \Drupal\Core\Render\ElementInfoManagerInterface $element_info
* The element info manager service.
*
* @todo Is this constructor necessary? Remove if it doesn't need to differ from parent.
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, ElementInfoManagerInterface $element_info) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings, $element_info);
}
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return [
'progress_indicator' => 'throbber',
] + parent::defaultSettings();
'progress_indicator' => 'throbber',
] + parent::defaultSettings();
}
/**
* Overrides \Drupal\file\Plugin\Field\FieldWidget\FileWidget::formMultipleElements().
* Overrides FileWidget::formMultipleElements().
*
* Special handling for draggable multiple widgets and 'add more' button.
*/
@ -64,10 +39,10 @@ class MediaTrackWidget extends FileWidget {
$cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
$file_upload_help = [
'#theme' => 'file_upload_help',
'#description' => '',
'#upload_validators' => $elements[0]['#upload_validators'],
'#cardinality' => $cardinality,
'#theme' => 'file_upload_help',
'#description' => '',
'#upload_validators' => $elements[0]['#upload_validators'],
'#cardinality' => $cardinality,
];
if ($cardinality == 1) {
// If there's only one field, return it as delta 0.
@ -84,9 +59,9 @@ class MediaTrackWidget extends FileWidget {
}
/**
* @inheritDoc
* {@inheritDoc}
*
* add the field settings so they can be used in the process method
* Add the field settings so they can be used in the process method.
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = parent::formElement($items, $delta, $element, $form, $form_state);
@ -129,27 +104,30 @@ class MediaTrackWidget extends FileWidget {
'#access' => (bool) $item['fids'],
];
$srclang_options = [];
$srclang_options = [];
if ($element['#field_settings']['languages'] == 'all') {
// need to list all languages
// Need to list all languages.
$languages = LanguageManager::getStandardLanguageList();
foreach ($languages AS $key => $language) {
foreach ($languages as $key => $language) {
if ($language[0] == $language[1]) {
// both the native language name and the English language name are
// the same, so only show one of them
// Both the native language name and the English language name are
// the same, so only show one of them.
$srclang_options[$key] = $language[0];
}
else {
// the native language name and English language name are different
// so show both of them
$srclang_options[$key] = t('@lang0 / @lang1', ['@lang0' => $language[0], '@lang1' => $language[1]]);
// The native language name and English language name are different
// so show both of them.
$srclang_options[$key] = t('@lang0 / @lang1', [
'@lang0' => $language[0],
'@lang1' => $language[1],
]);
}
}
}
else {
// only list the installed languages
// Only list the installed languages.
$languages = \Drupal::languageManager()->getLanguages();
foreach ($languages AS $key => $language) {
foreach ($languages as $key => $language) {
$srclang_options[$key] = $language->getName();
}
}
@ -164,7 +142,6 @@ class MediaTrackWidget extends FileWidget {
'#access' => (bool) $item['fids'],
'#element_validate' => [[get_called_class(), 'validateRequiredFields']],
];
// @todo checkbox or radio? Note this has unusual validation requirements!
// @see https://www.w3.org/TR/html/semantics-embedded-content.html#elementdef-track
$element['default'] = [
'#type' => 'checkbox',
@ -178,14 +155,11 @@ class MediaTrackWidget extends FileWidget {
}
/**
* Validate callback for kind/srclang/label/default
* Validate callback for kind/srclang/label/default.
*
* This is separated in a validate function instead of a #required flag to
* avoid being validated on the process callback.
*
* @todo Do we actually need anything here? This is copied from ImageWidget.
* Haven't yet decided if the extra inputs on media track are to be validated.
* The 'default' track boolean has complex validation, see the HTML5.2 rec for details.
* The 'default' track has complex validation, see HTML5.2 for details.
*/
public static function validateRequiredFields($element, FormStateInterface $form_state) {
// Only do validation if the function is triggered from other places than

Loading…
Cancel
Save