You are here

function claro_form_alter in Drupal 10

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

Implements hook_form_alter().

File

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

Code

function claro_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
  $build_info = $form_state
    ->getBuildInfo();
  $form_object = $form_state
    ->getFormObject();

  // Make entity forms delete link use the action-link component.
  if (isset($form['actions']['delete']['#type']) && $form['actions']['delete']['#type'] === 'link' && !empty($build_info['callback_object']) && $build_info['callback_object'] instanceof EntityForm) {
    $form['actions']['delete'] = _claro_convert_link_to_action_link($form['actions']['delete'], 'trash', 'default', 'danger');
  }
  if (($form_object instanceof ViewsForm || $form_object instanceof ViewsFormInterface) && isset($form['override']['#prefix'])) {

    // Replace form--inline class so positioning of override form elements don't
    // have to depend on floats.
    $form['override']['#prefix'] = str_replace('form--inline', 'form--flex', $form['override']['#prefix']);
  }
  if ($form_object instanceof ViewsForm && strpos($form_object
    ->getBaseFormId(), 'views_form_media_library') === 0) {
    if (isset($form['header'])) {
      $form['header']['#attributes']['class'][] = 'media-library-views-form__header';
      $form['header']['media_bulk_form']['#attributes']['class'][] = 'media-library-views-form__bulk_form';
    }
    $form['actions']['submit']['#attributes']['class'] = [
      'media-library-select',
    ];

    // The conditional below exists because the media-library-views-form class is
    // 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 https://www.drupal.org/node/3109287
    // @see classy_form_alter()
    if (!isset($form['#attributes']['class']) || !in_array('media-library-views-form', $form['#attributes']['class'])) {
      $form['#attributes']['class'][] = 'media-library-views-form';
    }
  }
}