Skip to content
Snippets Groups Projects
Commit 3d8cb502 authored by Jürgen Haas's avatar Jürgen Haas
Browse files

Revert "Issue #3310558 by mxh, antiden, jurgenhaas: How to set option in Book...

Revert "Issue #3310558 by mxh, antiden, jurgenhaas: How to set option in Book Outline after Create or Update node"

This reverts commit 32dd6ca4.
parent 46b9b117
No related branches found
No related tags found
No related merge requests found
......@@ -19,15 +19,6 @@ trait FormFieldPluginTrait {
use FormPluginTrait;
/**
* The lookup keys to use, respecting their occurring order.
*
* Values are either one of "parents" or "array_parents".
*
* @var string[]
*/
protected array $lookupKeys = ['parents', 'array_parents'];
/**
* Whether to use form field value filters or not.
*
......@@ -185,51 +176,9 @@ trait FormFieldPluginTrait {
$key = array_pop($name_array);
foreach ($this->lookupFormElements($form, $key) as &$element) {
if (empty($name_array) || (isset($element['#parents']) && array_intersect($name_array, $element['#parents']) === $name_array) || (isset($element['#array_parents']) && array_intersect($name_array, $element['#array_parents']) === $name_array)) {
// Found the element due to defined parents or array_parents.
if (empty($name_array) || (isset($element['#parents']) && $name_array === $element['#parents']) || (isset($element['#array_parents']) && $name_array === $element['#array_parents'])) {
return $element;
}
if (empty($name_array)) {
continue;
}
// For early form builds, parents and array_parents may not be available.
// For such a case, have another deep look into the render array.
$lookup = NULL;
$parents = [];
$lookup = static function (array &$elements, array &$name_array) use (&$lookup, &$parents) {
if ($parent = &NestedArray::getValue($elements, $name_array)) {
$parents[] = &$parent;
}
else {
foreach (Element::children($elements) as $c_key) {
$lookup($elements[$c_key], $name_array);
}
}
};
$lookup($form, $name_array);
foreach ($parents as &$parent) {
if (isset($parent[$key]) && ($parent[$key] === $element)) {
return $element;
}
}
unset($parent);
}
// Although not officially supported, try to get a target element using
// either "." or ":" as a separator for nested form elements. The official
// separator format is "][", which will be used for another try here.
// Not replacing "." and ":" at once, because there may be nested forms
// making use of both (e.g. "configuration.plugin.type:id").
$field_name = $this->configuration['field_name'];
if (mb_strpos($field_name, '.')) {
$this->configuration['field_name'] = str_replace('.', '][', $field_name);
return $this->getTargetElement();
}
if (mb_strpos($field_name, ':')) {
$this->configuration['field_name'] = str_replace(':', '][', $field_name);
return $this->getTargetElement();
}
return $nothing;
......@@ -289,45 +238,15 @@ trait FormFieldPluginTrait {
*/
protected function lookupFormElements(&$element, $key): array {
$found = [];
$lookup_keys = $this->lookupKeys;
foreach ($lookup_keys as $lookup_key) {
switch ($lookup_key) {
case 'parents':
$this->lookupKeys = ['parents'];
foreach (Element::children($element) as $child_key) {
if ((isset($element['#name']) && $element['#name'] === $key) || (isset($element['#parents']) && in_array($key, $element['#parents'], TRUE))) {
$found[] = &$element[$child_key];
}
else {
/* @noinspection SlowArrayOperationsInLoopInspection */
$found = array_merge($found, $this->lookupFormElements($element[$child_key], $key));
}
}
break;
case 'array_parents':
$this->lookupKeys = ['array_parents'];
// Alternatively, traverse along the keys of the form build array.
foreach (Element::children($element) as $child_key) {
if (($child_key === $key) || (isset($element['#array_parents']) && in_array($key, $element['#array_parents'], TRUE))) {
$found[] = &$element[$child_key];
}
else {
/* @noinspection SlowArrayOperationsInLoopInspection */
$found = array_merge($found, $this->lookupFormElements($element[$child_key], $key));
}
}
break;
foreach (Element::children($element) as $child_key) {
if (($child_key === $key) || (isset($element['#name']) && $element['#name'] === $key)) {
$found[] = &$element[$child_key];
}
if ($found) {
break;
else {
/* @noinspection SlowArrayOperationsInLoopInspection */
$found = array_merge($found, $this->lookupFormElements($element[$child_key], $key));
}
}
$this->lookupKeys = $lookup_keys;
return $found;
}
......@@ -353,26 +272,7 @@ trait FormFieldPluginTrait {
}
$found = FALSE;
$value = &$this->getFirstNestedOccurrence($field_name_array, $values, $found);
if (!$found) {
// Although not officially supported, try to get a submitted value using
// either "." or ":" as a separator for nested form elements. The official
// separator format is "][", which will be used for another try here.
// Not replacing "." and ":" at once, because there may be nested forms
// making use of both (e.g. "configuration.plugin.type:id").
$field_name = $this->configuration['field_name'];
if (mb_strpos($field_name, '.')) {
$this->configuration['field_name'] = str_replace('.', '][', $field_name);
return $this->getSubmittedValue($found);
}
if (mb_strpos($field_name, ':')) {
$this->configuration['field_name'] = str_replace(':', '][', $field_name);
return $this->getSubmittedValue($found);
}
}
return $value;
return $this->getFirstNestedOccurrence($field_name_array, $values, $found);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment