You are here

private function Update400::setUpFilterFormat in Lightning Media 8.4

Enables the media_embed filter on a single input format.

Parameters

\Drupal\filter\FilterFormatInterface $format: The input format.

1 call to Update400::setUpFilterFormat()
Update400::convertEditorsToMediaLibrary in src/Update/Update400.php
Optionally converts WYSIWYG editors to use the media library.

File

src/Update/Update400.php, line 153

Class

Update400
Contains optional updates targeting Lightning Media 4.0.0.

Namespace

Drupal\lightning_media\Update

Code

private function setUpFilterFormat(FilterFormatInterface $format) {
  $filters = $format
    ->filters();

  // If the format already has the media_embed filter, assume it is set up
  // correctly and bail out.
  $embed_filter = $filters
    ->get('media_embed');
  if ($embed_filter && $embed_filter->status) {
    return;
  }

  // If the HTML filter is enabled, ensure that it allows the custom embed
  // tag used by the media_embed filter.
  $html_filter = $filters
    ->get('filter_html');
  if ($html_filter && $html_filter->status) {
    $configuration = $html_filter
      ->getConfiguration();
    $configuration['settings']['allowed_html'] .= ' <drupal-media data-entity-type data-entity-uuid data-view-mode data-align data-caption alt>';
    $format
      ->setFilterConfig('filter_html', $configuration);
  }
  $format
    ->setFilterConfig('media_embed', [
    'settings' => [
      'default_view_mode' => 'embedded',
      'allowed_view_modes' => [],
    ],
    'status' => TRUE,
  ]);
  $this->entityTypeManager
    ->getStorage('filter_format')
    ->save($format);
}