You are here

lb_ux.module in Layout Builder UX 8

Contains lb_ux.module.

File

lb_ux.module
View source
<?php

/**
 * @file
 * Contains lb_ux.module.
 */
use Drupal\Core\Form\FormStateInterface;
use Drupal\layout_builder\Plugin\Block\InlineBlock;
use Drupal\lb_ux\Element\LayoutBuilderUX;
use Drupal\lb_ux\Form\FormAlter;
use Drupal\lb_ux\Plugin\Block\InlineBlockUX;

/**
 * Implements hook_element_plugin_alter().
 */
function lb_ux_element_plugin_alter(array &$definitions) {
  $definitions['layout_builder']['class'] = LayoutBuilderUX::class;
}

/**
 * Implements hook_block_alter().
 */
function lb_ux_block_alter(array &$definitions) {
  foreach ($definitions as &$definition) {
    if ($definition['class'] === InlineBlock::class) {
      $definition['class'] = InlineBlockUX::class;
    }
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function lb_ux_form_layout_builder_configure_section_alter(&$form, FormStateInterface $form_state, $form_id) {
  \Drupal::classResolver(FormAlter::class)
    ->alterConfigureForm($form, $form_state);
}

/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function lb_ux_form_layout_builder_configure_block_alter(&$form, FormStateInterface $form_state, $form_id) {
  \Drupal::classResolver(FormAlter::class)
    ->alterConfigureForm($form, $form_state);
}

/**
 * Implements hook_preprocess_HOOK() for the list of layouts.
 */
function lb_ux_preprocess_item_list__layouts(&$variables) {
  $layout_manager = \Drupal::service('plugin.manager.core.layout');

  // Replace the icons with smaller versions.
  foreach (array_keys($variables['items']) as $layout_id) {
    if (isset($variables['items'][$layout_id]['value']['#title']['icon'])) {
      $definition = $layout_manager
        ->getDefinition($layout_id);
      $variables['items'][$layout_id]['value']['#title']['icon'] = $definition
        ->getIcon(60, 40, 1, 3);
    }
  }
}