You are here

protected static function RegistrantsElementUtility::findElementWithProperties in RNG - Events and Registrations 8.2

Same name and namespace in other branches
  1. 8 src/RegistrantsElementUtility.php \Drupal\rng\RegistrantsElementUtility::findElementWithProperties()
  2. 3.x src/RegistrantsElementUtility.php \Drupal\rng\RegistrantsElementUtility::findElementWithProperties()

Traverses the triggering element tree until an element is found.

Traverses parents tree from the triggering element to find the element with the passed in properties.

Parameters

array $form: The complete form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

array $element_properties: Traverse up until finding an element with the properties with these keys and values.

Return value

array|null The requested element, or NULL if the element is not found.

1 call to RegistrantsElementUtility::findElementWithProperties()
RegistrantsElementUtility::findElement in src/RegistrantsElementUtility.php
Traverses the triggering element tree until this element is found.

File

src/RegistrantsElementUtility.php, line 72

Class

RegistrantsElementUtility

Namespace

Drupal\rng

Code

protected static function findElementWithProperties(array $form, FormStateInterface $form_state, array $element_properties) {
  $trigger = $form_state
    ->getTriggeringElement();
  $parents = $trigger['#parents'];

  // In case $form is the element itself.
  $element = $form;
  while (!isset($element) || array_diff_assoc($element_properties, $element)) {
    $element = NestedArray::getValue($form, $parents);
    if (array_pop($parents) === NULL) {
      return NULL;
    }
  }
  return $element;
}