Version 1
[yaffs-website] / web / themes / contrib / bootstrap / src / Plugin / Process / ActionsDropbutton.php
1 <?php
2 /**
3  * @file
4  * Contains \Drupal\bootstrap\Plugin\Process\ActionsDropbutton.
5  */
6
7 namespace Drupal\bootstrap\Plugin\Process;
8
9 use Drupal\bootstrap\Annotation\BootstrapProcess;
10 use Drupal\bootstrap\Utility\Element;
11 use Drupal\Core\Form\FormStateInterface;
12
13 /**
14  * Replaces the process callback for dropbuttons on an "actions" element.
15  *
16  * @ingroup plugins_process
17  *
18  * @BootstrapProcess("actions__dropbutton",
19  *   replace = "Drupal\Core\Render\Element\Actions::preRenderActionsDropbutton",
20  * )
21  *
22  * @see \Drupal\Core\Render\Element\Actions::preRenderActionsDropbutton()
23  *
24  * @todo This may become a #pre_render callback.
25  */
26 class ActionsDropbutton extends ProcessBase implements ProcessInterface {
27
28   /**
29    * {@inheritdoc}
30    */
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'];
38         }
39
40         $dropbuttons[$dropbutton]['#links'][$key] = $child->getArray();
41
42         // Remove original child from the element so it's not rendered twice.
43         $child->setProperty('printed', TRUE);
44       }
45     }
46     $element->exchangeArray($dropbuttons->getArray() + $element->getArray());
47   }
48
49 }