You are here

function claro_element_info_alter in Drupal 9

Same name and namespace in other branches
  1. 8 core/themes/claro/claro.theme \claro_element_info_alter()
  2. 10 core/themes/claro/claro.theme \claro_element_info_alter()

Implements hook_element_info_alter().

File

core/themes/claro/claro.theme, line 233
Functions to support theming in the Claro theme.

Code

function claro_element_info_alter(&$type) {

  // Add a pre-render function that handles the sidebar of the node form.
  // @todo Refactor when https://www.drupal.org/node/3056089 is in.
  if (isset($type['container'])) {
    $container_pre_renders = !empty($type['container']['#pre_render']) ? $type['container']['#pre_render'] : [];
    array_unshift($container_pre_renders, [
      ClaroPreRender::class,
      'container',
    ]);
    $type['container']['#pre_render'] = $container_pre_renders;
  }

  // @todo Refactor when https://www.drupal.org/node/3016343 is fixed.
  if (isset($type['text_format'])) {
    $type['text_format']['#pre_render'][] = [
      ClaroPreRender::class,
      'textFormat',
    ];
  }

  // Add a pre-render function for Operations to set #dropbutton_type.
  if (isset($type['operations'])) {

    // In Claro, Operations should always use the extrasmall dropbutton variant.
    // To add CSS classes based on variants, the element must have the
    // #dropbutton_type property before it is processed by
    // \Drupal\Core\Render\Element\Dropbutton::preRenderDropbutton(). This
    // ensures #dropbutton_type is available to preRenderDropbutton().
    $operations_pre_renders = !empty($type['operations']['#pre_render']) ? $type['operations']['#pre_render'] : [];
    array_unshift($operations_pre_renders, [
      ClaroPreRender::class,
      'operations',
    ]);
    $type['operations']['#pre_render'] = $operations_pre_renders;
  }
  if (isset($type['vertical_tabs'])) {
    $type['vertical_tabs']['#pre_render'][] = [
      ClaroPreRender::class,
      'verticalTabs',
    ];
  }

  // Add a pre-render to managed_file.
  if (isset($type['managed_file'])) {
    $type['managed_file']['#pre_render'][] = [
      ClaroPreRender::class,
      'managedFile',
    ];
  }

  // Add a pre-render to status_messages to alter the placeholder markup.
  if (isset($type['status_messages'])) {
    $type['status_messages']['#pre_render'][] = [
      ClaroPreRender::class,
      'messagePlaceholder',
    ];
  }
}