Unverified Commit 46281c68 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3046152 by kim.pepper, rajab natshah, aleevas, chris_wearebraid,...

Issue #3046152 by kim.pepper, rajab natshah, aleevas, chris_wearebraid, jpschroeder, hchonov, ranjith_kumar_k_u, oily, smustgrave, alexpott, pandaski, catch: Add playsinline option to Video media file formatter
parent 9c2b7d9d
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -366,6 +366,7 @@ pickable
pingback
placeholdered
placeholdering
playsinline
plusthick
porterstemmer
postcondition
+3 −0
Original line number Diff line number Diff line
@@ -133,6 +133,9 @@ field.formatter.settings.file_video:
    muted:
      type: boolean
      label: 'Muted'
    playsinline:
      type: boolean
      label: 'Plays inline'
    width:
      type: integer
      label: 'Width'
+10 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
use Drupal\Core\Template\Attribute;
use Drupal\file\FileInterface;
use Drupal\file\IconMimeTypes;
use Drupal\file\Plugin\Field\FieldFormatter\FileVideoFormatter;
use Drupal\file\Upload\FileUploadHandlerInterface;
use Drupal\file\Upload\FormUploadedFile;

@@ -765,3 +766,12 @@ function file_system_settings_submit(array &$form, FormStateInterface $form_stat
    ->set('filename_sanitization', $form_state->getValue('filename_sanitization'));
  $config->save();
}

/**
 * Implements hook_ENTITY_TYPE_presave().
 */
function file_file_video_presave(FileVideoFormatter $formatter): void {
  if ($formatter->getSetting('playsinline') === NULL) {
    $formatter->setSetting('playsinline', FALSE);
  }
}
+24 −0
Original line number Diff line number Diff line
@@ -5,6 +5,10 @@
 * Post update functions for File.
 */

use Drupal\Core\Config\Entity\ConfigEntityUpdater;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Implements hook_removed_post_updates().
 */
@@ -15,3 +19,23 @@ function file_removed_post_updates(): array {
    'file_post_update_add_default_filename_sanitization_configuration' => '11.0.0',
  ];
}

/**
 * Adds a value for the 'playsinline' setting of the 'file_video' formatter.
 */
function file_post_update_add_playsinline(array &$sandbox = []): ?TranslatableMarkup {
  /** @var \Drupal\Core\Config\Entity\ConfigEntityUpdater $config_entity_updater */
  $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class);
  return $config_entity_updater->update($sandbox, 'entity_view_display', function (EntityViewDisplayInterface $display) {
    $needs_update = FALSE;
    $components = $display->getComponents();
    foreach ($components as $name => $component) {
      if (isset($component['type']) && $component['type'] === 'file_video') {
        $needs_update = TRUE;
        $component['settings']['playsinline'] = FALSE;
        $display->setComponent($name, $component);
      }
    }
    return $needs_update;
  });
}
+8 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ public static function getMediaType() {
  public static function defaultSettings() {
    return [
      'muted' => FALSE,
      'playsinline' => FALSE,
      'width' => 640,
      'height' => 480,
    ] + parent::defaultSettings();
@@ -47,6 +48,11 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
        '#type' => 'checkbox',
        '#default_value' => $this->getSetting('muted'),
      ],
      'playsinline' => [
        '#title' => $this->t('Plays Inline'),
        '#type' => 'checkbox',
        '#default_value' => $this->getSetting('playsinline'),
      ],
      'width' => [
        '#type' => 'number',
        '#title' => $this->t('Width'),
@@ -76,6 +82,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
  public function settingsSummary() {
    $summary = parent::settingsSummary();
    $summary[] = $this->t('Muted: %muted', ['%muted' => $this->getSetting('muted') ? $this->t('yes') : $this->t('no')]);
    $summary[] = $this->t('Plays Inline: %playsinline', ['%playsinline' => $this->getSetting('playsinline') ? $this->t('yes') : $this->t('no')]);

    if ($width = $this->getSetting('width')) {
      $summary[] = $this->t('Width: %width pixels', [
@@ -96,7 +103,7 @@ public function settingsSummary() {
   * {@inheritdoc}
   */
  protected function prepareAttributes(array $additional_attributes = []) {
    $attributes = parent::prepareAttributes(['muted']);
    $attributes = parent::prepareAttributes(['muted', 'playsinline']);
    if (($width = $this->getSetting('width'))) {
      $attributes->setAttribute('width', $width);
    }
Loading