currentUser = $current_user; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['label'], $configuration['view_mode'], $configuration['third_party_settings'], $container->get('current_user') ); } /** * {@inheritdoc} */ public static function defaultSettings() { return array( 'width' => '854', 'height' => '480', 'controls' => TRUE, 'autoplay' => FALSE, 'loop' => FALSE, 'muted' => FALSE, 'preload' => 'none' ) + parent::defaultSettings(); } /** * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { $element['width'] = [ '#title' => t('Width'), '#type' => 'textfield', '#default_value' => $this->getSetting('width'), '#required' => TRUE, ]; $element['height'] = [ '#title' => t('Height'), '#type' => 'textfield', '#default_value' => $this->getSetting('height'), '#required' => TRUE, ]; $element['controls'] = [ '#title' => t('Show controls'), '#type' => 'checkbox', '#default_value' => $this->getSetting('controls'), ]; $element['autoplay'] = [ '#title' => t('Autoplay'), '#type' => 'checkbox', '#default_value' => $this->getSetting('autoplay'), ]; $element['loop'] = [ '#title' => t('Loop'), '#type' => 'checkbox', '#default_value' => $this->getSetting('loop'), ]; $element['muted'] = [ '#title' => t('Muted'), '#type' => 'checkbox', '#default_value' => $this->getSetting('muted'), ]; $element['preload'] = [ '#title' => t('Preload'), '#type' => 'select', '#default_value' => $this->getSetting('preload'), '#options' => array( 'none' =>'none', 'metadata' => 'metadata', 'auto' => 'auto' ), '#description' => t('Hint to the browser about whether optimistic downloading of the video itself or its metadata is considered worthwhile.') ]; return $element; } /** * {@inheritdoc} */ public function settingsSummary() { $summary = array(); $summary[] = t('HTML5 Video (@widthx@height@controls@autoplay@loop@muted).', [ '@width' => $this->getSetting('width'), '@height' => $this->getSetting('height'), '@controls' => $this->getSetting('controls') ? t(', controls') : '' , '@autoplay' => $this->getSetting('autoplay') ? t(', autoplaying') : '' , '@loop' => $this->getSetting('loop') ? t(', looping') : '' , '@muted' => $this->getSetting('muted') ? t(', muted') : '', ]); return $summary; } /** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { $elements = array(); $files = $this->getEntitiesToView($items, $langcode); // Early opt-out if the field is empty. if (empty($files)) { return $elements; } // Collect cache tags to be added for each item in the field. foreach ($files as $delta => $file) { $video_uri = $file->getFileUri(); $elements[$delta] = array( '#theme' => 'videojs', '#items' => array(Url::fromUri(file_create_url($video_uri))), '#player_attributes' => $this->getSettings(), '#attached' => array( 'library' => array('videojs/videojs'), ), ); } return $elements; } /** * {@inheritdoc} */ public static function isApplicable(FieldDefinitionInterface $field_definition) { return !$field_definition->isList(); } }