You are here

function entity_embed_update_8003 in Entity Embed 8

Updates allowed HTML for all filter configs that have an Entity Embed button.

File

./entity_embed.install, line 62
Contains install and update functions for Entity Embed.

Code

function entity_embed_update_8003() {
  $buttons = \Drupal::entityTypeManager()
    ->getStorage('embed_button')
    ->loadMultiple();
  $filter_formats_with_embed_button = [];

  // Get filter formats from editors with entity embed button.
  foreach (\Drupal::entityTypeManager()
    ->getStorage('editor')
    ->loadMultiple() as $editor) {
    foreach (new RecursiveIteratorIterator(new RecursiveArrayIterator($editor
      ->getSettings())) as $settings_value) {
      foreach ($buttons as $button) {
        if ($settings_value == $button
          ->id()) {
          $filter_formats_with_embed_button[] = $editor
            ->getFilterFormat();
        }
      }
    }
  }
  foreach ($filter_formats_with_embed_button as $filter_format) {
    foreach ($filter_format
      ->filters()
      ->getAll() as $filter) {
      if (isset($filter
        ->getConfiguration()['settings']['allowed_html'])) {
        $allowed_html = $filter
          ->getConfiguration()['settings']['allowed_html'];
        if (strpos($allowed_html, 'data-entity-embed-settings')) {
          $allowed_html = str_replace('data-entity-embed-settings', 'data-entity-embed-settings data-entity-embed-display-settings', $allowed_html);
          $filter_format
            ->setFilterConfig($filter
            ->getPluginId(), [
            'settings' => [
              'allowed_html' => $allowed_html,
            ],
          ]);
          $filter_format
            ->save();
        }
      }
    }
  }
}