ClaroPreRender.php in Drupal 10
File
core/themes/claro/src/ClaroPreRender.php
View source
<?php
namespace Drupal\claro;
use Drupal\Core\Render\Element;
use Drupal\Core\Security\TrustedCallbackInterface;
class ClaroPreRender implements TrustedCallbackInterface {
public static function managedFile($element) {
if (!empty($element['remove_button']) && is_array($element['remove_button'])) {
$element['remove_button']['#attributes']['class'][] = 'button--extrasmall';
$element['remove_button']['#attributes']['class'][] = 'remove-button';
}
if (!empty($element['upload_button']) && is_array($element['upload_button'])) {
$element['upload_button']['#attributes']['class'][] = 'upload-button';
}
$single_file_widget = empty($element['#do_not_wrap_in_details']) && !empty($element['#cardinality']) && $element['#cardinality'] === 1;
if ($single_file_widget && empty($element['#single_wrapped'])) {
$element['#theme_wrappers']['details'] = [
'#title' => $element['#title'],
'#summary_attributes' => [],
'#attributes' => [
'open' => TRUE,
],
'#value' => NULL,
'#description' => NULL,
'#required' => $element['#required'],
'#errors' => NULL,
'#disabled' => !empty($element['#disabled']),
];
$element['#single_wrapped'] = TRUE;
$upload_is_accessible = empty($element['#default_value']['fids']) && (!isset($element['upload']['#access']) || $element['upload']['#access'] !== FALSE);
if ($upload_is_accessible) {
$element['#title'] = t('Add a new file');
}
else {
$element['#title_display'] = 'invisible';
}
}
return $element;
}
public static function verticalTabs($element) {
$group_type_is_details = isset($element['group']['#type']) && $element['group']['#type'] === 'details';
$groups_are_present = isset($element['group']['#groups']) && is_array($element['group']['#groups']);
if ($group_type_is_details && $groups_are_present) {
$group_keys = Element::children($element['group']['#groups'], TRUE);
$first_key = TRUE;
$last_group_with_child_key = NULL;
$last_group_with_child_key_last_child_key = NULL;
$group_key = implode('][', $element['#parents']);
if (in_array($group_key, $group_keys)) {
$children_keys = Element::children($element['group']['#groups'][$group_key], TRUE);
foreach ($children_keys as $child_key) {
$last_group_with_child_key = $group_key;
$type = $element['group']['#groups'][$group_key][$child_key]['#type'] ?? NULL;
if ($type === 'details') {
$element['group']['#groups'][$group_key][$child_key]['#attributes']['class'][] = 'vertical-tabs__item';
$element['group']['#groups'][$group_key][$child_key]['#vertical_tab_item'] = TRUE;
if ($first_key) {
$element['group']['#groups'][$group_key][$child_key]['#attributes']['class'][] = 'vertical-tabs__item--first';
$first_key = FALSE;
}
$last_group_with_child_key_last_child_key = $child_key;
}
}
}
if ($last_group_with_child_key && $last_group_with_child_key_last_child_key) {
$element['group']['#groups'][$last_group_with_child_key][$last_group_with_child_key_last_child_key]['#attributes']['class'][] = 'vertical-tabs__item--last';
}
$element['#attributes']['class'][] = 'vertical-tabs__items';
}
return $element;
}
public static function operations($element) {
if (empty($element['#dropbutton_type'])) {
$element['#dropbutton_type'] = 'extrasmall';
}
return $element;
}
public static function container(array $element) {
if (!empty($element['#accordion'])) {
$element['#attributes']['class'][] = 'accordion';
$children_keys = Element::children($element['#groups']['advanced'], TRUE);
foreach ($children_keys as $key) {
$element['#groups']['advanced'][$key]['#attributes']['class'][] = 'accordion__item';
if (!empty($element['#groups']['advanced'][$key]['#type']) && $element['#groups']['advanced'][$key]['#type'] === 'details') {
$element['#groups']['advanced'][$key]['#accordion_item'] = TRUE;
}
}
}
return $element;
}
public static function textFormat($element) {
$element['format']['#attributes']['class'][] = 'clearfix';
$element['format']['format']['#wrapper_attributes']['class'][] = 'form-item--editor-format';
$element['format']['format']['#attributes']['class'][] = 'form-element--extrasmall';
$element['format']['format']['#attributes']['class'][] = 'form-element--editor-format';
if (!empty($element['summary']) && $element['summary']['#type'] === 'textarea') {
$element['#attributes']['class'][] = 'js-text-format-wrapper';
$element['value']['#wrapper_attributes']['class'][] = 'js-form-type-textarea';
}
return $element;
}
public static function messagePlaceholder(array $element) {
if (isset($element['fallback']['#markup'])) {
$element['fallback']['#markup'] = '<div data-drupal-messages-fallback class="hidden messages-list"></div>';
}
return $element;
}
public static function trustedCallbacks() {
return [
'managedFile',
'verticalTabs',
'operations',
'container',
'textFormat',
'messagePlaceholder',
];
}
}
Classes
Name |
Description |
ClaroPreRender |
Implements trusted prerender callbacks for the Claro theme. |