You are here

protected function YamlForm::deleteElementRecursive in YAML Form 8

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 YamlForm::deleteElementRecursive()
YamlForm::deleteElement in src/Entity/YamlForm.php
Remove an element.

File

src/Entity/YamlForm.php, line 1021

Class

YamlForm
Defines the form entity.

Namespace

Drupal\yamlform\Entity

Code

protected function deleteElementRecursive(array &$elements, $key) {
  foreach ($elements as $element_key => &$element) {
    if (Element::property($element_key) || !is_array($element)) {
      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;
}