#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.
array $element: The #type 'actions' element to process.
array The processed #type 'actions' element, including individual buttons grouped into new #type 'dropbutton' elements.
function form_pre_render_actions_dropbutton(array $element) {
$dropbuttons = array();
foreach (element_children($element, TRUE) as $key) {
if (isset($element[$key]['#dropbutton'])) {
$dropbutton = $element[$key]['#dropbutton'];
// If there is no dropbutton for this button group yet, create one.
if (!isset($dropbuttons[$dropbutton])) {
$dropbuttons[$dropbutton] = array(
'#type' => 'dropbutton',
);
}
// Add this button to the corresponding dropbutton.
// @todo Change #type 'dropbutton' to be based on theme_item_list()
// instead of theme_links() to avoid this preemptive rendering.
$button = drupal_render($element[$key]);
$dropbuttons[$dropbutton]['#links'][$key] = array(
'title' => $button,
'html' => TRUE,
);
}
}
// @todo For now, all dropbuttons appear first. Consider to invent a more
// fancy sorting/injection algorithm here.
return $dropbuttons + $element;
}