file ActionsDropbutton.php

Namespace

Drupal\bootstrap\Plugin\Process
  1. <?php
  2. namespace Drupal\bootstrap\Plugin\Process;
  3. use Drupal\bootstrap\Utility\Element;
  4. use Drupal\Core\Form\FormStateInterface;
  5. /**
  6. * Replaces the process callback for dropbuttons on an "actions" element.
  7. *
  8. * @ingroup plugins_process
  9. *
  10. * @BootstrapProcess("actions__dropbutton",
  11. * replace = "Drupal\Core\Render\Element\Actions::preRenderActionsDropbutton",
  12. * )
  13. *
  14. * @see \Drupal\Core\Render\Element\Actions::preRenderActionsDropbutton()
  15. *
  16. * @see https://www.drupal.org/node/2855458
  17. *
  18. * @todo Remove once core is fixed.
  19. */
  20. class ActionsDropbutton extends ProcessBase implements ProcessInterface {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public static function processElement(Element $element, FormStateInterface $form_state, array &$complete_form) {
  25. $dropbuttons = Element::create();
  26. foreach ($element->children(TRUE) as $key => $child) {
  27. if ($dropbutton = $child->getProperty('dropbutton')) {
  28. // If there is no dropbutton for this button group yet, create one.
  29. if (!isset($dropbuttons->$dropbutton)) {
  30. $dropbuttons->$dropbutton = ['#type' => 'dropbutton'];
  31. }
  32. $dropbuttons[$dropbutton]['#links'][$key] = ['title' => $child->getArray()];
  33. // Remove original child from the element so it's not rendered twice.
  34. $child->setProperty('printed', TRUE);
  35. }
  36. }
  37. $element->exchangeArray($dropbuttons->getArray() + $element->getArray());
  38. }
  39. }

Classes

Name Description
ActionsDropbutton Replaces the process callback for dropbuttons on an "actions" element.