You are here

function layout_builder_modal_link_alter in Layout Builder Modal 8

Implements hook_link_alter().

File

./layout_builder_modal.module, line 43
Contains layout_builder_modal.module.

Code

function layout_builder_modal_link_alter(&$variables) {

  /** @var Drupal\Core\Url $url */
  $url = $variables['url'];
  if (!$url
    ->isRouted()) {
    return;
  }
  $route_name = $url
    ->getRouteName();
  if ($route_name !== 'layout_builder.add_block' && $route_name !== 'layout_builder.update_block') {
    return;
  }
  if (!in_array('use-ajax', $variables['options']['attributes']['class'], TRUE)) {
    return;
  }
  $config = \Drupal::config('layout_builder_modal.settings');
  $data_dialog_options = Json::encode([
    'width' => $config
      ->get('modal_width'),
    'height' => $config
      ->get('modal_height'),
    'target' => 'layout-builder-modal',
    'autoResize' => $config
      ->get('modal_autoresize'),
    'modal' => TRUE,
  ]);
  $variables['options']['attributes']['data-dialog-options'] = $data_dialog_options;
  $variables['options']['attributes']['data-dialog-type'] = 'dialog';
  unset($variables['options']['attributes']['data-dialog-renderer']);
}