function SubformState::getParents
Same name in other branches
- 9 core/lib/Drupal/Core/Form/SubformState.php \Drupal\Core\Form\SubformState::getParents()
- 8.9.x core/lib/Drupal/Core/Form/SubformState.php \Drupal\Core\Form\SubformState::getParents()
- 10 core/lib/Drupal/Core/Form/SubformState.php \Drupal\Core\Form\SubformState::getParents()
Gets the subform's parents relative to its parent form.
Parameters
string $property: The property name (#parents or #array_parents).
Return value
mixed The form parents relative to its parent form.
Throws
\InvalidArgumentException Thrown when the requested property does not exist.
\UnexpectedValueException Thrown when the subform is not contained by the given parent form.
3 calls to SubformState::getParents()
- SubformState::getLimitValidationErrors in core/
lib/ Drupal/ Core/ Form/ SubformState.php - Retrieves the limited validation error sections.
- SubformState::getValues in core/
lib/ Drupal/ Core/ Form/ SubformState.php - Implements \Drupal\Core\Form\FormStateInterface::getValues()
- SubformState::setLimitValidationErrors in core/
lib/ Drupal/ Core/ Form/ SubformState.php - Sets the limited validation error sections.
File
-
core/
lib/ Drupal/ Core/ Form/ SubformState.php, line 78
Class
- SubformState
- Stores information about the state of a subform.
Namespace
Drupal\Core\FormCode
protected function getParents($property) {
foreach ([
$this->subform,
$this->parentForm,
] as $form) {
if (!isset($form[$property]) || !is_array($form[$property])) {
throw new \RuntimeException(sprintf('The subform and parent form must contain the %s property, which must be an array. Try calling this method from a #process callback instead.', $property));
}
}
$relative_subform_parents = $this->subform[$property];
// Remove all of the subform's parents that are also the parent form's
// parents, so we are left with the parents relative to the parent form.
foreach ($this->parentForm[$property] as $parent_form_parent) {
if ($parent_form_parent !== $relative_subform_parents[0]) {
// The parent form's parents are the subform's parents as well. If we
// find no match, that means the given subform is not contained by the
// given parent form.
throw new \UnexpectedValueException('The subform is not contained by the given parent form.');
}
array_shift($relative_subform_parents);
}
return $relative_subform_parents;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.