4 * Contains \Drupal\bootstrap\Plugin\Process\ActionsDropbutton.
7 namespace Drupal\bootstrap\Plugin\Process;
9 use Drupal\bootstrap\Annotation\BootstrapProcess;
10 use Drupal\bootstrap\Utility\Element;
11 use Drupal\Core\Form\FormStateInterface;
14 * Replaces the process callback for dropbuttons on an "actions" element.
16 * @ingroup plugins_process
18 * @BootstrapProcess("actions__dropbutton",
19 * replace = "Drupal\Core\Render\Element\Actions::preRenderActionsDropbutton",
22 * @see \Drupal\Core\Render\Element\Actions::preRenderActionsDropbutton()
24 * @todo This may become a #pre_render callback.
26 class ActionsDropbutton extends ProcessBase implements ProcessInterface {
31 public static function processElement(Element $element, FormStateInterface $form_state, array &$complete_form) {
32 $dropbuttons = Element::create();
33 foreach ($element->children(TRUE) as $key => $child) {
34 if ($dropbutton = $child->getProperty('dropbutton')) {
35 // If there is no dropbutton for this button group yet, create one.
36 if (!isset($dropbuttons->$dropbutton)) {
37 $dropbuttons->$dropbutton = ['#type' => 'dropbutton'];
40 $dropbuttons[$dropbutton]['#links'][$key] = $child->getArray();
42 // Remove original child from the element so it's not rendered twice.
43 $child->setProperty('printed', TRUE);
46 $element->exchangeArray($dropbuttons->getArray() + $element->getArray());