public static function SimpleActions::preRenderActionsDropbutton in Entity reference actions 1.x
#pre_render callback for #type 'actions'.
This callback iterates over all child elements of the #type 'actions' container to look for elements with a #dropbutton property, so as to group those elements into dropbuttons. As such, it works similar to #group, but is specialized for dropbuttons.
The value of #dropbutton denotes the dropbutton to group the child element into. For example, two different values of 'foo' and 'bar' on child elements would generate two separate dropbuttons, which each contain the corresponding buttons.
Parameters
array $element: The #type 'actions' element to process.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
array $complete_form: The complete form structure.
Return value
array The processed #type 'actions' element, including individual buttons grouped into new #type 'dropbutton' elements.
Overrides Actions::preRenderActionsDropbutton
File
- src/
Element/ SimpleActions.php, line 26
Class
- SimpleActions
- Action element without primary classes.
Namespace
Drupal\entity_reference_actions\ElementCode
public static function preRenderActionsDropbutton(&$element, FormStateInterface $form_state, &$complete_form) {
// Because we are cloning the elements into title sub element we need to
// sort children first.
$dropbuttons = [];
foreach (Element::children($element, TRUE) as $key) {
if (isset($element[$key]['#dropbutton'])) {
$dropbutton = $element[$key]['#dropbutton'];
if (!isset($dropbuttons[$dropbutton])) {
$dropbuttons[$dropbutton] = [
'#type' => 'ajax_dropbutton',
];
}
$dropbuttons[$dropbutton]['#links'][$key] = [
'title' => $element[$key],
];
// Clone the element as an operation.
$operations[$key] = [
'title' => $element[$key],
];
// Flag the original element as printed so it doesn't render twice.
$element[$key]['#printed'] = TRUE;
}
}
// @todo For now, all dropbuttons appear first. Consider to invent a more
// fancy sorting/injection algorithm here.
return $dropbuttons + $element;
}