function FormHooks::formAfterBuild
Same name and namespace in other branches
- 11.x core/themes/admin/src/Hook/FormHooks.php \Drupal\admin\Hook\FormHooks::formAfterBuild()
Helper function to remember the form actions after form has been built.
File
-
core/
themes/ admin/ src/ Hook/ FormHooks.php, line 814
Class
- FormHooks
- Provides form related hook implementations.
Namespace
Drupal\admin\HookCode
public static function formAfterBuild(array $form) : array {
if (self::useStickyActionButtons()) {
// Allowlist for visible actions.
$includes = [
'save',
'submit',
'preview',
];
// Build actions.
foreach (Element::children($form['actions']) as $key) {
$button = $form['actions'][$key] ?? [];
if (!($button['#access'] ?? TRUE)) {
continue;
}
$navigation_enabled = \Drupal::service('module_handler')->moduleExists('navigation');
if ($navigation_enabled) {
$form['gin_sticky_actions']['actions'][$key] = $button;
}
// The media_type_add_form form is a special case.
// @see https://www.drupal.org/project/gin/issues/3534385
// @see \Drupal\media\MediaTypeForm::actions
if (isset($button['#type']) && $button['#type'] === 'submit' || $form['#form_id'] === 'media_type_add_form') {
// Update button.
$button['#attributes']['id'] = 'gin-sticky-' . $button['#id'];
$button['#attributes']['form'] = $form['#id'];
$button['#attributes']['data-drupal-selector'] = 'gin-sticky-' . $button['#attributes']['data-drupal-selector'];
$button['#attributes']['data-gin-sticky-form-selector'] = $button['#attributes']['data-drupal-selector'];
// Add the button to the form actions array.
if (!empty($button['#gin_action_item']) || $navigation_enabled || in_array($key, $includes, TRUE)) {
$form['gin_sticky_actions']['actions'][$key] = $button;
}
}
}
}
Helper::formActions($form['gin_sticky_actions'] ?? NULL);
unset($form['gin_sticky_actions']);
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.