function PreprocessHooks::details

Same name and namespace in other branches
  1. main core/themes/admin/src/Hook/PreprocessHooks.php \Drupal\admin\Hook\PreprocessHooks::details()

Implements hook_preprocess_HOOK() for details.

Attributes

#[Hook('preprocess_details')]

File

core/themes/admin/src/Hook/PreprocessHooks.php, line 313

Class

PreprocessHooks
Provides preprocess implementations.

Namespace

Drupal\admin\Hook

Code

public function details(array &$variables) : void {
  // @todo Revisit when https://www.drupal.org/node/3056089 is in.
  $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'], $variables['errors']) && $element['#errors'] === $variables['errors']) {
      unset($variables['errors']);
    }
  }
  $variables['disabled'] = !empty($element['#disabled']);
  $this->preprocessDescriptionToggle($variables);
}

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