You are here

public static function Element::disableButtons in Lightning Core 8

Same name and namespace in other branches
  1. 8.5 src/Element.php \Drupal\lightning_core\Element::disableButtons()
  2. 8.2 src/Element.php \Drupal\lightning_core\Element::disableButtons()
  3. 8.3 src/Element.php \Drupal\lightning_core\Element::disableButtons()
  4. 8.4 src/Element.php \Drupal\lightning_core\Element::disableButtons()

Pre-render function to disable all buttons in a renderable element.

Parameters

array $element: The renderable element.

Return value

array The renderable element with all buttons (at all levels) disabled.

File

src/Element.php, line 80

Class

Element
Helpful functions for dealing with renderable arrays and elements.

Namespace

Drupal\lightning_core

Code

public static function disableButtons(array $element) {
  if (isset($element['#type'])) {
    $element['#access'] = !in_array($element['#type'], [
      'button',
      'submit',
      'image_button',
    ]);
  }

  // Recurse into child elements.
  foreach (RenderElement::children($element) as $key) {
    if (is_array($element[$key])) {
      $element[$key] = static::disableButtons($element[$key]);
    }
  }
  return $element;
}