You are here

protected function Webform::deleteElementRecursive in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Entity/Webform.php \Drupal\webform\Entity\Webform::deleteElementRecursive()

Remove an element by key from a render array.

Parameters

array $elements: An associative nested array of elements.

string $key: The element's key.

Return value

bool|array An array containing the deleted element and sub element keys. FALSE is no sub elements are found.

1 call to Webform::deleteElementRecursive()
Webform::deleteElement in src/Entity/Webform.php
Remove an element.

File

src/Entity/Webform.php, line 1966

Class

Webform
Defines the webform entity.

Namespace

Drupal\webform\Entity

Code

protected function deleteElementRecursive(array &$elements, $key) {
  foreach ($elements as $element_key => &$element) {

    // Make sure the element key is a string.
    $element_key = (string) $element_key;
    if (!WebformElementHelper::isElement($element, $element_key)) {
      continue;
    }
    if ($element_key === $key) {
      $sub_element_keys = [
        $element_key => $element_key,
      ];
      $this
        ->collectSubElementKeysRecursive($sub_element_keys, $element);
      unset($elements[$element_key]);
      return $sub_element_keys;
    }
    if ($sub_element_keys = $this
      ->deleteElementRecursive($element, $key)) {
      return $sub_element_keys;
    }
  }
  return FALSE;
}