View source
<?php
namespace Drupal\file\Plugin\Field\FieldFormatter;
use Drupal\Core\Form\FormStateInterface;
class FileVideoFormatter extends FileMediaFormatterBase {
public static function getMediaType() {
return 'video';
}
public static function defaultSettings() {
return [
'muted' => FALSE,
'width' => 640,
'height' => 480,
] + parent::defaultSettings();
}
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,
],
];
}
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;
}
protected function prepareAttributes(array $additional_attributes = []) {
return parent::prepareAttributes([
'muted',
])
->setAttribute('width', $this
->getSetting('width'))
->setAttribute('height', $this
->getSetting('height'));
}
}