You are here

gin_lb.module in Gin Layout Builder 1.0.x

Provides hooks for gin_lb module.

File

gin_lb.module
View source
<?php

/**
 * @file
 * Provides hooks for gin_lb module.
 */
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Asset\AttachedAssetsInterface;
use Drupal\views\ViewExecutable;

/**
 * Implements hook_preprocess_form_element().
 */
function gin_lb_preprocess_form_element(array &$variables) {
  if (!isset($variables['label'])) {
    return;
  }
  if (isset($variables['element']['#gin_lb_form'])) {
    $variables['label']['#gin_lb_form'] = TRUE;
    if (isset($variables['element']['#type'])) {
      $variables['attributes']['class'][] = 'form-type--' . $variables['element']['#type'];
    }
  }
}

/**
 * Returns true if the current theme is not gin.
 *
 * @return bool
 *   return true if gin === 'false'
 */
function gin_lb_is_valid_theme() {

  /** @var \Drupal\Core\Theme\ThemeManagerInterface $theme_manager */
  $theme_manager = \Drupal::service('theme.manager');
  $active_theme = $theme_manager
    ->getActiveTheme();
  if ($active_theme
    ->getName() === 'gin' || array_key_exists('gin', $active_theme
    ->getBaseThemeExtensions())) {
    return FALSE;
  }
  return TRUE;
}

/**
 * Returns true if the given form id should rendered in gin style.
 *
 * @param string $form_id
 *   The form id.
 * @param array $form
 *   The form.
 *
 * @return bool
 *   True for gin form.
 */
function gin_lb_is_layout_builder_form_id($form_id, array $form) {
  if (gin_lb_is_valid_theme() === FALSE) {
    return FALSE;
  }
  $form_ids = [
    'layout_builder_add_block',
    'views_form_media_library_widget_image',
    'media_image_edit_form',
    'media_library_add_form_upload',
    'layout_builder_add_block',
    'layout_builder_remove_block',
    'layout_builder_update_block',
    'layout_builder_block_move',
    'layout_builder_configure_section',
    'form-autocomplete',
  ];
  $form_id_contains = [
    'layout_builder_translate_form',
  ];
  foreach ($form_id_contains as $form_id_contain) {
    if (strpos($form_id, $form_id_contain) !== FALSE) {
      return TRUE;
    }
  }
  if (in_array($form_id, $form_ids)) {
    return TRUE;
  }
  if ($form_id === 'views_exposed_form' && isset($form['#id']) && $form['#id'] === 'views-exposed-form-media-library-widget') {
    return TRUE;
  }
  if (strpos($form_id, 'layout_builder_form') !== FALSE) {
    return TRUE;
  }
  return FALSE;
}

/**
 * Implements hook_module_implements_alter().
 */
function gin_lb_module_implements_alter(&$implementations, $hook) {
  switch ($hook) {
    case 'suggestions_alter':
    case 'form_alter':
      $group = $implementations['gin_lb'];
      unset($implementations['gin_lb']);
      $implementations['gin_lb'] = $group;
      break;
  }
}

/**
 * Implements hook_views_pre_render().
 */
function gin_lb_views_pre_render(ViewExecutable $view) {
  if (gin_lb_is_valid_theme() === FALSE) {
    return;
  }
  $add_classes = function (&$option, array $classes_to_add) {
    $classes = preg_split('/\\s+/', $option);
    $classes = array_filter($classes);
    $classes = array_merge($classes, $classes_to_add);
    $option = implode(' ', array_unique($classes));
  };
  if ($view
    ->id() === 'media_library') {
    if ($view->display_handler->options['defaults']['css_class']) {
      $add_classes($view->displayHandlers
        ->get('default')->options['css_class'], [
        'media-library-view',
      ]);
    }
    else {
      $add_classes($view->display_handler->options['css_class'], [
        'media-library-view',
      ]);
    }
    if ($view->current_display === 'page') {
      if (array_key_exists('media_bulk_form', $view->field)) {
        $add_classes($view->field['media_bulk_form']->options['element_class'], [
          'media-library-item__click-to-select-checkbox',
        ]);
      }
      if (array_key_exists('rendered_entity', $view->field)) {
        $add_classes($view->field['rendered_entity']->options['element_class'], [
          'media-library-item__content',
        ]);
      }
      if (array_key_exists('edit_media', $view->field)) {
        $add_classes($view->field['edit_media']->options['alter']['link_class'], [
          'media-library-item__edit',
        ]);
        $add_classes($view->field['edit_media']->options['alter']['link_class'], [
          'icon-link',
        ]);
      }
      if (array_key_exists('delete_media', $view->field)) {
        $add_classes($view->field['delete_media']->options['alter']['link_class'], [
          'media-library-item__remove',
        ]);
        $add_classes($view->field['delete_media']->options['alter']['link_class'], [
          'icon-link',
        ]);
      }
    }
    elseif (strpos($view->current_display, 'widget') === 0) {
      if (array_key_exists('rendered_entity', $view->field)) {
        $add_classes($view->field['rendered_entity']->options['element_class'], [
          'media-library-item__content',
        ]);
      }
      if (array_key_exists('media_library_select_form', $view->field)) {
        $add_classes($view->field['media_library_select_form']->options['element_wrapper_class'], [
          'media-library-item__click-to-select-checkbox',
        ]);
      }
      if ($view->display_handler->options['defaults']['css_class']) {
        $add_classes($view->displayHandlers
          ->get('default')->options['css_class'], [
          'media-library-view--widget',
        ]);
      }
      else {
        $add_classes($view->display_handler->options['css_class'], [
          'media-library-view--widget',
        ]);
      }
    }
  }
}

/**
 * Implements hook_theme_suggestions_alter().
 */
function gin_lb_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
  if (gin_lb_is_valid_theme() === FALSE) {
    return;
  }
  $add_suggestions = FALSE;
  $route_name = \Drupal::routeMatch()
    ->getRouteName();
  if (in_array($route_name, [
    'layout_builder.add_block',
    'layout_builder.choose_block',
    'layout_builder.choose_inline_block',
    'layout_builder.remove_section',
    'layout_builder.remove_block',
    'layout_builder.choose_section',
    'view.media_library.widget_table',
    'view.media_library.widget',
    'media_library.ui',
    'editor.media_dialog',
    'editor.link_dialog',
    'editor.image_dialog',
  ])) {
    $add_suggestions = TRUE;
  }

  // For ajax the route is views.ajax
  // So a look to the suggestions help.
  if ($route_name === 'views.ajax') {
    if (\Drupal::request()->query
      ->get('media_library_opener_id')) {
      $add_suggestions = TRUE;
    }
    $view = isset($variables['view']) && $variables['view'] instanceof ViewExecutable;
    if ($view && $variables['view']
      ->id() === 'media_library') {
      $add_suggestions = TRUE;
    }
    if ($hook === 'media' && $variables['elements']['#view_mode'] === 'media_library') {
      $add_suggestions = TRUE;
    }
  }
  if (gin_lb_is_layout_builder_route() && in_array($hook, [
    'status_messages',
    'media_library_wrapper',
    'views_view',
    'views_view_unformatted',
    'media',
    'views_mini_pager',
    'pager',
  ])) {
    $add_suggestions = TRUE;
  }
  if (isset($variables['element']['#gin_lb_form']) || $add_suggestions === TRUE) {

    // Fix form element suggestions when they are not implemented in the theme.
    if (empty($suggestions) && !empty($variables['theme_hook_original'])) {
      $suggestions = [
        $variables['theme_hook_original'],
      ];
    }
    $additional_suggestions = [];
    foreach ($suggestions as $suggestion) {
      $additional_suggestions[] = $suggestion . '__gin_lb';
    }
    $suggestions[] = $hook . '__gin_lb';
    $suggestions = array_merge($suggestions, $additional_suggestions);
    if (isset($variables['view']) && $hook === 'views_view_unformatted') {
      $suggestions[] = $hook . '__' . $variables['view']
        ->id() . '__gin_lb';
    }
  }
}

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function gin_lb_theme_suggestions_form_alter(array &$suggestions, array $variables) {
  if (gin_lb_is_valid_theme() === FALSE) {
    return;
  }
  if (strpos($variables['element']['#form_id'], 'layout_builder_form') !== FALSE) {
    $route_name = \Drupal::routeMatch()
      ->getRouteName();
    $gin_lb_show_toolbar = TRUE;
    \Drupal::moduleHandler()
      ->alter('gin_lb_show_toolbar', $gin_lb_show_toolbar);

    // Disable toolbar for layout library.
    // Layout builder is part of the layout library form.
    if (strpos($route_name, 'layout_builder.layout_library.') !== 0 && $gin_lb_show_toolbar === TRUE) {
      $suggestions[] = 'form__layout_builder_form__gin_lb';
    }
  }
}

/**
 * After build form process.
 *
 * Layout builder forms are attached later to setting form.
 * To add suggestion to the attached fields we have to attach lb_form
 * after build.
 *
 * @param array $form
 *   The form.
 *
 * @return array
 *   The form.
 */
function gin_lb_after_build(array $form) {
  gin_lb_attach_lb_form($form);
  return $form;
}

/**
 * Implements hook_form_alter().
 */
function gin_lb_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if (gin_lb_is_valid_theme() === FALSE) {
    return;
  }
  if (gin_lb_is_layout_builder_form_id($form_id, $form)) {
    $form['#after_build'][] = 'gin_lb_after_build';
    $form['#gin_lb_form'] = TRUE;
    $form['#attributes']['class'][] = 'glb-form';
  }
  if (strpos($form_id, 'layout_builder_form') !== FALSE) {
    $form['advanced']['#type'] = 'container';
    $form['actions']['preview_toggle']['toggle_content_preview']['#title'] = t('Preview');
    $form['actions']['configure'] = [
      '#type' => 'markup',
      '#markup' => '<div class="glb-configure"></div>',
      '#weight' => -100,
    ];
    $weight = $form["actions"]["preview_toggle"]["#weight"] ?? 0;
    $form['actions']['preview_regions'] = [
      '#type' => 'checkbox',
      '#title' => t('Regions'),
      '#weight' => $weight + 1,
      '#id' => 'glb-preview-regions',
    ];
  }
  if (in_array($form_id, [
    'layout_builder_update_block',
    'layout_builder_add_block',
    'layout_builder_configure_section',
    'layout_builder_remove_section',
    'layout_builder_remove_block',
  ])) {
    $form['#attributes']['class'][] = 'canvas-form';
    if (isset($form['settings'])) {
      $form['settings']['#type'] = 'container';
      $form['settings']['#attributes']['class'][] = 'canvas-form__settings';
    }
    if (isset($form['layout_settings'])) {
      $form['layout_settings']['#type'] = 'container';
      $form['layout_settings']['#attributes']['class'][] = 'canvas-form__settings';
    }
    if (in_array($form_id, [
      'layout_builder_remove_block',
      'layout_builder_remove_section',
    ])) {
      $form['description']['#type'] = 'container';
      $form['description']['#attributes']['class'][] = 'canvas-form__settings';
    }
    $form['actions']['#type'] = 'container';
    $form['actions']['#attributes']['class'][] = 'canvas-form__actions';
  }
}

/**
 * Returns true if the current route is a layout builder route.
 *
 * @return bool
 *   Returns true for layout builder routes.
 */
function gin_lb_is_layout_builder_route() {
  $gin_lb_is_layout_builder_route = drupal_static(__FUNCTION__);
  if ($gin_lb_is_layout_builder_route !== NULL) {
    return $gin_lb_is_layout_builder_route;
  }
  $rout_match = \Drupal::routeMatch();
  $route_name = $rout_match
    ->getRouteName();
  $gin_lb_is_layout_builder_route = FALSE;
  if (preg_match('/^(layout_builder\\.([^.]+\\.)?)/', $route_name)) {
    $gin_lb_is_layout_builder_route = TRUE;
  }
  \Drupal::moduleHandler()
    ->alter('gin_lb_is_layout_builder_route', $gin_lb_is_layout_builder_route, $context);
  return $gin_lb_is_layout_builder_route;
}

/**
 * Attaches gin_lb_form to all layout builder form elements.
 *
 * @param array $form
 *   The form or form element which children should have form id attached.
 */
function gin_lb_attach_lb_form(array &$form) {
  foreach (Element::children($form) as $child) {
    if (!isset($form[$child]['#gin_lb_form'])) {
      $form[$child]['#gin_lb_form'] = TRUE;
    }
    gin_lb_attach_lb_form($form[$child]);
  }
}

/**
 * Implements hook_page_attachments().
 */
function gin_lb_page_attachments(array &$attachments) {
  if (gin_lb_is_layout_builder_route()) {
    $attachments['#attached']['library'][] = 'gin_lb/gin_lb_init';
    $attachments['#attached']['library'][] = 'gin/gin_ckeditor';
    $attachments['#attached']['library'][] = 'claro/claro.jquery.ui';
    $attachments['#attached']['library'][] = 'claro/claro.drupal.dialog';
    $attachments['#attached']['library'][] = 'gin_lb/gin_lb_form';
    $config = \Drupal::config('gin_lb.settings');
    if ($config
      ->get('toastify_cdn')) {
      $attachments['#attached']['library'][] = 'gin_lb/toastify';
    }
  }
}

/**
 * A list of all overwritten themes.
 *
 * @return array
 *   List of overwritten themes.
 */
function gin_lb_overwritten_themes() {
  return [
    'form/form',
    'form/input',
    'form/form-element-label',
    'form/form-element',
    'form/container',
    'form/input--checkbox',
    'form/checkboxes',
    'form/details',
    'form/radios',
    'form/select',
    'form/field-multiple-value-form',
    'form/text-format-wrapper',
    'form/fieldset',
    'form/textarea',
    'links',
    'media-library/container--media-library-content',
    'media-library/container--media-library-widget-selection',
    'media-library/details--media-library-add-form-selected-media',
    'media-library/item-list--media-library-add-form-media-list',
    'media-library/links--media-library-menu',
    'media-library/media--media-library',
    'media-library/media-library-item',
    'media-library/media-library-wrapper',
    'media-library/views-view--media-library',
    'media-library/views-view-table',
    'media-library/media-library-element',
    'media-library/views-view-unformatted--media-library',
    'item-list',
    'table',
    'status-messages',
    'views-mini-pager',
    'pager',
  ];
}

/**
 * Implements hook_preprocess_media_library_item__widget().
 *
 * This targets each media item selected in an entity reference field.
 */
function gin_lb_preprocess_media_library_item(array &$variables) {
  if (gin_lb_is_valid_theme() === FALSE) {
    return;
  }
  $variables['content']['remove_button']['#attributes']['class'][] = 'media-library-item__remove';
  $variables['content']['remove_button']['#attributes']['class'][] = 'icon-link';
}

/**
 * Implements hook_preprocess_links__media_library_menu().
 *
 * This targets the menu of available media types in the media library's modal
 * dialog.
 *
 * @todo Do this in the relevant template once
 *   https://www.drupal.org/project/drupal/issues/3088856 is resolved.
 */
function gin_lb_preprocess_links__media_library_menu(array &$variables) {
  if (gin_lb_is_valid_theme() === FALSE) {
    return;
  }
  foreach ($variables['links'] as &$link) {

    // Add a class to the Media Library menu items.
    $link['attributes']
      ->addClass('glb-media-library-menu__item');

    // This conditional exists because the media-library-menu__link class is
    // currently added by Classy, but Claro will eventually not use Classy as a
    // base theme.
    // @todo remove conditional, keep class addition in
    //   https://drupal.org/node/3110137
    // @see classy_preprocess_links__media_library_menu()
    if (!isset($link['link']['#options']['attributes']['class']) || !in_array('glb-media-library-menu__link', $link['link']['#options']['attributes']['class'])) {
      $link['link']['#options']['attributes']['class'][] = 'glb-media-library-menu__link';
    }
  }
}

/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function gin_lb_form_media_library_add_form_alter(array &$form, FormStateInterface $form_state) {
  $form['#attributes']['class'][] = 'media-library-add-form';

  // If there are unsaved media items, apply styling classes to various parts
  // of the form.
  if (isset($form['media'])) {
    $form['#attributes']['class'][] = 'media-library-add-form--with-input';

    // Put a wrapper around the informational message above the unsaved media
    // items.
    $form['description']['#template'] = '<p class="glb-media-library-add-form__description">{{ text }}</p>';
  }
  else {
    $form['#attributes']['class'][] = 'media-library-add-form--without-input';
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function gin_lb_form_media_library_add_form_upload_alter(array &$form, FormStateInterface $form_state) {
  $form['#attributes']['class'][] = 'media-library-add-form--upload';
  if (isset($form['container']['upload'])) {

    // Set this flag so we can prevent the details element from being added
    // in \Drupal\claro\ClaroPreRender::managedFile.
    $form['container']['upload']['#do_not_wrap_in_details'] = TRUE;
  }
  if (isset($form['container'])) {
    $form['container']['#attributes']['class'][] = 'media-library-add-form__input-wrapper';
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function gin_lb_form_media_library_add_form_oembed_alter(array &$form, FormStateInterface $form_state) {
  $form['#attributes']['class'][] = 'media-library-add-form--oembed';

  // If no media items have been added yet, add a couple of styling classes
  // to the initial URL form.
  if (isset($form['container'])) {
    $form['container']['#attributes']['class'][] = 'media-library-add-form__input-wrapper';
    $form['container']['url']['#attributes']['class'][] = 'media-library-add-form-oembed-url';
    $form['container']['submit']['#attributes']['class'][] = 'media-library-add-form-oembed-submit';
  }
}

/**
 * Implements hook_preprocess_item_list__media_library_add_form_media_list().
 *
 * This targets each new, unsaved media item added to the media library, before
 * they are saved.
 */
function gin_lb_preprocess_item_list__media_library_add_form_media_list(array &$variables) {
  foreach ($variables['items'] as &$item) {
    $item['value']['preview']['#attributes']['class'][] = 'media-library-add-form__preview';
    $item['value']['fields']['#attributes']['class'][] = 'media-library-add-form__fields';
    $item['value']['remove_button']['#attributes']['class'][] = 'media-library-add-form__remove-button';
    $item['value']['remove_button']['#attributes']['class'][] = 'button--extrasmall';

    // #source_field_name is set by AddFormBase::buildEntityFormElement()
    // to help themes and form_alter hooks identify the source field.
    $fields =& $item['value']['fields'];
    $source_field_name = $fields['#source_field_name'];

    // Set this flag so we can remove the details element.
    $fields[$source_field_name]['widget'][0]['#do_not_wrap_in_details'] = TRUE;
    if (isset($fields[$source_field_name])) {
      $fields[$source_field_name]['#attributes']['class'][] = 'media-library-add-form__source-field';
    }
  }
}

/**
 * Implements hook_preprocess_media_library_item__widget().
 *
 * This targets each media item selected in an entity reference field.
 */
function gin_lb_preprocess_media_library_item__widget(array &$variables) {
  $variables['content']['remove_button']['#attributes']['class'][] = 'media-library-item__remove';
  $variables['content']['remove_button']['#attributes']['class'][] = 'icon-link';
}

/**
 * Implements template_preprocess_HOOK() for table.
 */
function gin_lb_preprocess_table(&$variables) {
  if (isset($variables['attributes']['class']) && in_array('glb-table', $variables['attributes']['class'], TRUE)) {

    // Adding table sort indicator CSS class for inactive sort link.
    // @todo Revisit after https://www.drupal.org/node/3025726 or
    // https://www.drupal.org/node/1973418 is in.
    if (!empty($variables['header'])) {
      foreach ($variables['header'] as &$header_cell) {
        if ($header_cell['content'] instanceof Link) {
          $query = $header_cell['content']
            ->getUrl()
            ->getOption('query') ?: [];
          if (isset($query['order']) && isset($query['sort'])) {
            $header_cell['attributes']
              ->addClass('sortable-heading');
          }
        }
      }
    }

    // Mark the whole table and the first cells if rows are draggable.
    if (!empty($variables['rows'])) {
      $draggable_row_found = FALSE;
      foreach ($variables['rows'] as &$row) {

        /** @var \Drupal\Core\Template\Attribute $row ['attributes'] */
        if (!empty($row['attributes']) && $row['attributes']
          ->hasClass('draggable')) {
          if (!$draggable_row_found) {
            $variables['attributes']['class'][] = 'draggable-table';
            $draggable_row_found = TRUE;
          }
          reset($row['cells']);
          $first_cell_key = key($row['cells']);

          // The 'attributes' key is always here and it is an
          // \Drupal\Core\Template\Attribute.
          // @see template_preprocess_table();
          $row['cells'][$first_cell_key]['attributes']
            ->addClass('tabledrag-cell');

          // Check that the first cell is empty or not.
          if (empty($row['cells'][$first_cell_key]) || empty($row['cells'][$first_cell_key]['content'])) {
            $row['cells'][$first_cell_key]['attributes']
              ->addClass('tabledrag-cell--only-drag');
          }
        }
      }
    }
    if ($draggable_row_found) {
      $variables['#attached']['library'][] = 'gin/gin_tabledrag';
    }
  }
}

/**
 * Implements template_preprocess_HOOK() for field_ui_table.
 */
function gin_lb_preprocess_field_ui_table(&$variables) {
  gin_lb_preprocess_table($variables);
}

/**
 * Implements hook_preprocess_HOOK() for field_multiple_value_form.
 */
function gin_lb_preprocess_field_multiple_value_form(&$variables) {

  // Add gin_lb_form attribute to tables.
  if ($variables['element']['#gin_lb_form'] ?? NULL) {
    $variables['table']['#attributes']['class'][] = 'glb-table';

    // Make disabled available for the template.
    $variables['disabled'] = !empty($variables['element']['#disabled']);
    if ($variables['multiple']) {

      // Add an additional CSS class for the field label table cell.
      // This repeats the logic of template_preprocess_field_multiple_value_form()
      // without using '#prefix' and '#suffix' for the wrapper element.
      //
      // If the field is multiple, we don't have to check the existence of the
      // table header cell.
      //
      // @see template_preprocess_field_multiple_value_form().
      $header_attributes = [
        'class' => [
          'form-item__label',
          'form-item__label--multiple-value-form',
        ],
      ];
      if (!empty($variables['element']['#required'])) {
        $header_attributes['class'][] = 'js-form-required';
        $header_attributes['class'][] = 'form-required';
      }

      // Using array_key_first() for addressing the first header cell would be
      // more elegant here, but we can rely on the related theme.inc preprocess.
      $variables['table']['#header'][0]['data'] = [
        '#type' => 'html_tag',
        '#tag' => 'h4',
        '#value' => $variables['element']['#title'],
        '#attributes' => $header_attributes,
      ];
      if ($variables['disabled']) {
        $variables['table']['#attributes']['class'][] = 'tabledrag-disabled';
        $variables['table']['#attributes']['class'][] = 'js-tabledrag-disabled';

        // We will add the 'is-disabled' CSS class to the disabled table header
        // cells.
        $header_attributes['class'][] = 'is-disabled';
        foreach ($variables['table']['#header'] as &$cell) {
          if (is_array($cell) && isset($cell['data'])) {
            $cell = $cell + [
              'class' => [],
            ];
            $cell['class'][] = 'is-disabled';
          }
          else {

            // We have to modify the structure of this header cell.
            $cell = [
              'data' => $cell,
              'class' => [
                'is-disabled',
              ],
            ];
          }
        }
      }

      // Make add-more button smaller.
      if (!empty($variables['button'])) {
        $variables['button']['#attributes']['class'][] = 'button--small';
      }
    }
  }
}

/**
 * Implements hook_theme().
 */
function gin_lb_theme($existing, $type, $theme, $path) {
  $overwritten_themes = gin_lb_overwritten_themes();
  $themes = [];
  foreach ($overwritten_themes as $overwritten_theme) {
    $overwritten_hook_ary = explode('/', str_replace('-', '_', $overwritten_theme));
    $overwritten_hook = $overwritten_hook_ary[count($overwritten_hook_ary) - 1];
    $overwritten_base_hook = explode('--', $overwritten_hook)[0];
    $themes[$overwritten_hook . '__gin_lb'] = [
      'template' => $overwritten_theme . '--gin-lb',
      'base hook' => $overwritten_base_hook,
    ];
  }
  $themes['form__layout_builder_form__gin_lb'] = [
    'template' => 'form/form--layout-builder-form--gin-lb',
    'base hook' => 'form',
  ];
  return $themes;
}

/**
 * Implements hook_css_alter().
 */
function gin_lb_css_alter(&$css, AttachedAssetsInterface $assets) {
  $theme_handler = \Drupal::service('theme_handler');

  // Only target layout builder specific pages.
  if (gin_lb_is_layout_builder_route()) {
    $stable_themes = [
      'stable',
      'stable9',
    ];
    foreach ($stable_themes as $stable_theme) {
      if ($theme_handler
        ->themeExists($stable_theme)) {
        $stable_theme_css = drupal_get_path('theme', $stable_theme) . '/css';

        // Remove very specific CSS files that this module is overriding.
        unset($css[$stable_theme_css . '/layout_builder/layout-builder.css']);
        unset($css[$stable_theme_css . '/core/dialog/off-canvas.theme.css']);
        unset($css[$stable_theme_css . '/core/dialog/off-canvas.details.css']);
        unset($css[$stable_theme_css . '/core/dialog/off-canvas.reset.css']);
        unset($css[$stable_theme_css . '/core/dialog/off-canvas.base.css']);
        unset($css[$stable_theme_css . '/core/dialog/off-canvas.table.css']);
        unset($css[$stable_theme_css . '/core/dialog/off-canvas.tabledrag.css']);
        unset($css[$stable_theme_css . '/core/dialog/off-canvas.form.css']);
        unset($css[$stable_theme_css . '/core/dialog/off-canvas.button.css']);

        // unset($css[$stable_theme_css . '/core/vertical-tabs.css']);.
      }
    }
    unset($css['core/modules/layout_builder/css/layout-builder.css']);
    unset($css['core/modules/system/css/components/tabledrag.module.css']);
    unset($css['core/assets/vendor/jquery.ui/themes/base/dialog.css']);
    unset($css['core/misc/dialog/off-canvas.theme.css']);
    unset($css['core/misc/dialog/off-canvas.base.css']);
    unset($css['core/misc/dialog/off-canvas.reset.css']);
    unset($css['core/misc/dialog/off-canvas.table.css']);
    unset($css['core/misc/dialog/off-canvas.tabledrag.css']);
    unset($css['core/misc/dialog/off-canvas.details.css']);
    unset($css['core/misc/dialog/off-canvas.form.css']);
    unset($css['core/misc/dialog/off-canvas.button.css']);
    unset($css['core/assets/vendor/jquery.ui/themes/base/theme.css']);
  }
}

Functions

Namesort descending Description
gin_lb_after_build After build form process.
gin_lb_attach_lb_form Attaches gin_lb_form to all layout builder form elements.
gin_lb_css_alter Implements hook_css_alter().
gin_lb_form_alter Implements hook_form_alter().
gin_lb_form_media_library_add_form_alter Implements hook_form_BASE_FORM_ID_alter().
gin_lb_form_media_library_add_form_oembed_alter Implements hook_form_FORM_ID_alter().
gin_lb_form_media_library_add_form_upload_alter Implements hook_form_FORM_ID_alter().
gin_lb_is_layout_builder_form_id Returns true if the given form id should rendered in gin style.
gin_lb_is_layout_builder_route Returns true if the current route is a layout builder route.
gin_lb_is_valid_theme Returns true if the current theme is not gin.
gin_lb_module_implements_alter Implements hook_module_implements_alter().
gin_lb_overwritten_themes A list of all overwritten themes.
gin_lb_page_attachments Implements hook_page_attachments().
gin_lb_preprocess_field_multiple_value_form Implements hook_preprocess_HOOK() for field_multiple_value_form.
gin_lb_preprocess_field_ui_table Implements template_preprocess_HOOK() for field_ui_table.
gin_lb_preprocess_form_element Implements hook_preprocess_form_element().
gin_lb_preprocess_item_list__media_library_add_form_media_list Implements hook_preprocess_item_list__media_library_add_form_media_list().
gin_lb_preprocess_links__media_library_menu Implements hook_preprocess_links__media_library_menu().
gin_lb_preprocess_media_library_item Implements hook_preprocess_media_library_item__widget().
gin_lb_preprocess_media_library_item__widget Implements hook_preprocess_media_library_item__widget().
gin_lb_preprocess_table Implements template_preprocess_HOOK() for table.
gin_lb_theme Implements hook_theme().
gin_lb_theme_suggestions_alter Implements hook_theme_suggestions_alter().
gin_lb_theme_suggestions_form_alter Implements hook_theme_suggestions_HOOK_alter().
gin_lb_views_pre_render Implements hook_views_pre_render().