lb_claro-8.x-1.0-beta3/lb_claro.module

lb_claro.module
<?php

/**
 * @file
 * Hooks for LB Claro module.
 */

use Drupal\Core\Asset\AttachedAssetsInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\layout_builder\Form\DefaultsEntityForm;
use Drupal\layout_builder\Form\OverridesEntityForm;

/**
 * Implements hook_form_alter().
 */
function lb_claro_form_alter(&$form, FormStateInterface $form_state, $form_id): void {
  $form_object = $form_state->getFormObject();
  if ($form_object instanceof OverridesEntityForm || $form_object instanceof DefaultsEntityForm
    || $form_object->getFormId() === 'layout_layout_builder_form'
  ) {
    $form['#attached']['library'][] = 'claro/global-styling';
    $form['#attached']['library'][] = 'lb_claro/layout_builder';
    $form['#attached']['library'][] = 'claro/claro.drupal.dialog';
    $form['#attached']['library'][] = 'claro/media_library.theme';
    $form['#attached']['library'][] = 'lb_claro/off_canvas';
    $form['#attached']['library'][] = 'lb_claro/media_library';
    $form['#attached']['library'][] = 'lb_claro/entity_forms';
  }

  // Add layout-builder-form to layout library save form.
  if ($form_object->getFormId() === 'layout_layout_builder_form') {
    $form['#attributes']['class'][] = 'layout-builder-form';
  }
}

/**
 * Implements hook_css_alter().
 */
function lb_claro_css_alter(&$css, AttachedAssetsInterface $assets): void {
  $route_name = \Drupal::routeMatch()->getRouteName();
  $theme_handler = \Drupal::service('theme_handler');

  // Only target layout builder specific pages.
  if (preg_match('/^(layout_builder\.([^.]+\.)?)/', $route_name)) {
    // Unset Claro CSS files.
    $claro_css = \Drupal::service('extension.list.theme')->getPath('claro') . '/css';
    if ($theme_handler->themeExists('claro')) {
      foreach ($css as $key => $item) {
        $css_to_keep = [
          $claro_css . '/base/variables.css',
          $claro_css . '/components/toolbar.module.css',
          $claro_css . '/state/toolbar.menu.css',
          $claro_css . '/theme/toolbar.theme.css',
          $claro_css . '/theme/toolbar.icons.theme.css',
          $claro_css . '/components/icon-link.css',
          $claro_css . '/components/dialog.css',
          $claro_css . '/theme/media-library.css',
        ];
        if (str_starts_with($key, $claro_css) && !in_array($key, $css_to_keep)) {
          unset($css[$key]);
        }
      }
    }

    // Remove very specific CSS files that this module is overriding.
    $stable_themes = ['stable', 'stable9'];
    foreach ($stable_themes as $stable_theme) {
      if ($theme_handler->themeExists($stable_theme)) {
        $stable_theme_css = \Drupal::service('extension.list.theme')->getPath($stable_theme) . '/css';
        unset($css[$stable_theme_css . '/layout_builder/layout-builder.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.form.css']);
        unset($css[$stable_theme_css . '/core/dialog/off-canvas.button.css']);
        unset($css[$stable_theme_css . '/core/dialog/off-canvas.details.css']);
      }
    }

    // Remove jquery ui CSS files that this module is overriding.
    unset($css['core/assets/vendor/jquery.ui/themes/base/dialog.css']);
    unset($css['core/assets/vendor/jquery.ui/themes/base/theme.css']);
  }
}

/**
 * Implements hook_theme_registry_alter().
 */
function lb_claro_theme_registry_alter(&$theme_registry): void {
  $claro_path = \Drupal::service('extension.list.theme')->getPath('claro');

  // Add media-library templates directly copied from Claro.
  $theme_registry['views_view__media_library__widget'] = $theme_registry['views_view'];
  $theme_registry['views_view__media_library__widget']['template'] = 'views-view--media-library';
  $theme_registry['views_view__media_library__widget']['path'] = $claro_path . '/templates/media-library';

  $theme_registry['views_view__media_library__widget_table'] = $theme_registry['views_view'];
  $theme_registry['views_view__media_library__widget_table']['template'] = 'views-view--media-library';
  $theme_registry['views_view__media_library__widget_table']['path'] = $claro_path . '/templates/media-library';

  $theme_registry['views_view_unformatted__media_library'] = $theme_registry['views_view_unformatted'];
  $theme_registry['views_view_unformatted__media_library']['template'] = 'views-view-unformatted--media-library';
  $theme_registry['views_view_unformatted__media_library']['path'] = $claro_path . '/templates/media-library';

  $theme_registry['media_library_wrapper']['template'] = 'media-library-wrapper';
  $theme_registry['media_library_wrapper']['path'] = $claro_path . '/templates/classy/media-library';

  $theme_registry['container__media_library_content'] = $theme_registry['container'];
  $theme_registry['container__media_library_content']['template'] = 'container--media-library-content';
  $theme_registry['container__media_library_content']['path'] = $claro_path . '/templates/classy/media-library';

  $theme_registry['media__media_library']['template'] = 'media--media-library';
  $theme_registry['media__media_library']['path'] = $claro_path . '/templates/media-library';
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc