function ClaroHooks::preprocessDetails

Same name and namespace in other branches
  1. 11.x core/themes/claro/src/Hook/ClaroHooks.php \Drupal\claro\Hook\ClaroHooks::preprocessDetails()

Implements hook_preprocess_HOOK() for details.

@todo Revisit when https://www.drupal.org/node/3056089 is in.

Attributes

#[Hook('preprocess_details')]

File

core/themes/claro/src/Hook/ClaroHooks.php, line 357

Class

ClaroHooks
Hook implementations for claro.

Namespace

Drupal\claro\Hook

Code

public function preprocessDetails(&$variables) : void {
  $element = $variables['element'];
  if (!empty($element['#accordion_item'])) {
    // Details should appear as an accordion item.
    $variables['accordion_item'] = TRUE;
  }
  if (!empty($element['#accordion'])) {
    // Details should appear as a standalone accordion.
    $variables['accordion'] = TRUE;
  }
  if (!empty($element['#theme']) && $element['#theme'] === 'file_widget_multiple') {
    // Mark the details required if needed. If the file widget allows
    // uploading multiple files, the required state is checked by checking
    // the state of the first child.
    $variables['required'] = $element[0]['#required'] ?? !empty($element['#required']);
    // If the error is the same as the one in the multiple field widget
    // element, we have to avoid displaying it twice. Stark has this issue as
    // well. @todo Revisit when https://www.drupal.org/node/3084906 is fixed.
    if (isset($element['#errors']) && isset($variables['errors']) && $element['#errors'] === $variables['errors']) {
      unset($variables['errors']);
    }
  }
  $variables['disabled'] = !empty($element['#disabled']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.