3 namespace Drupal\file\Plugin\Field\FieldFormatter;
5 use Drupal\Core\Form\FormStateInterface;
8 * Plugin implementation of the 'file_video' formatter.
12 * label = @Translation("Video"),
13 * description = @Translation("Display the file using an HTML5 video tag."),
19 class FileVideoFormatter extends FileMediaFormatterBase {
24 public static function getMediaType() {
31 public static function defaultSettings() {
36 ] + parent::defaultSettings();
42 public function settingsForm(array $form, FormStateInterface $form_state) {
43 return parent::settingsForm($form, $form_state) + [
45 '#title' => $this->t('Muted'),
46 '#type' => 'checkbox',
47 '#default_value' => $this->getSetting('muted'),
51 '#title' => $this->t('Width'),
52 '#default_value' => $this->getSetting('width'),
55 '#field_suffix' => $this->t('pixels'),
61 '#title' => $this->t('Height'),
62 '#default_value' => $this->getSetting('height'),
65 '#field_suffix' => $this->t('pixels'),
75 public function settingsSummary() {
76 $summary = parent::settingsSummary();
77 $summary[] = $this->t('Muted: %muted', ['%muted' => $this->getSetting('muted') ? $this->t('yes') : $this->t('no')]);
78 $summary[] = $this->t('Size: %width x %height pixels', [
79 '%width' => $this->getSetting('width'),
80 '%height' => $this->getSetting('height'),
88 protected function prepareAttributes(array $additional_attributes = []) {
89 return parent::prepareAttributes(['muted'])
90 ->setAttribute('width', $this->getSetting('width'))
91 ->setAttribute('height', $this->getSetting('height'));