You are here

function lightning_media_js_settings_alter in Lightning Media 8.4

Same name and namespace in other branches
  1. 8 lightning_media.module \lightning_media_js_settings_alter()
  2. 8.2 lightning_media.module \lightning_media_js_settings_alter()
  3. 8.3 lightning_media.module \lightning_media_js_settings_alter()

Implements hook_js_settings_alter().

File

./lightning_media.module, line 381
Core media asset support for Lightning.

Code

function lightning_media_js_settings_alter(array &$settings) {
  if (empty($settings['ajax'])) {
    $settings['ajax'] = [];
  }
  $route_name = \Drupal::routeMatch()
    ->getRouteName();
  if (strpos($route_name, 'entity_browser') === 0 && isset($settings['ajaxPageState']['libraries'])) {
    $libraries = explode(',', $settings['ajaxPageState']['libraries']);

    // If we pretend EB's iframe library has not been previously loaded, it will
    // ALWAYS be fetched from the server, preventing (in a crappy, kludgey way)
    // the bug in #2768849.
    $libraries = array_diff($libraries, [
      'entity_browser/iframe',
    ]);
    $settings['ajaxPageState']['libraries'] = implode(',', $libraries);
  }
}