Skip to content
Snippets Groups Projects
Commit 6fc6b5cd authored by Pierre Dureau's avatar Pierre Dureau
Browse files

Avoid magic numbers in ComponentSlotsForm

parent ef4f2c94
No related branches found
No related tags found
No related merge requests found
...@@ -234,7 +234,11 @@ class ComponentSlotsForm extends ComponentFormBase { ...@@ -234,7 +234,11 @@ class ComponentSlotsForm extends ComponentFormBase {
*/ */
public static function refreshAfterSourceAddition(array $form, FormStateInterface $form_state) { public static function refreshAfterSourceAddition(array $form, FormStateInterface $form_state) {
$parents = $form_state->getTriggeringElement()['#array_parents']; $parents = $form_state->getTriggeringElement()['#array_parents'];
$form = NestedArray::getValue($form, array_slice($parents, 0, -2)); $form_layers = count([
"(source)",
"add_more_button",
]);
$form = NestedArray::getValue($form, array_slice($parents, 0, -$form_layers));
return $form['sources']; return $form['sources'];
} }
...@@ -257,7 +261,13 @@ class ComponentSlotsForm extends ComponentFormBase { ...@@ -257,7 +261,13 @@ class ComponentSlotsForm extends ComponentFormBase {
*/ */
final public static function refreshAfterSourceRemoval(array $form, FormStateInterface $form_state) { final public static function refreshAfterSourceRemoval(array $form, FormStateInterface $form_state) {
$parents = $form_state->getTriggeringElement()['#array_parents']; $parents = $form_state->getTriggeringElement()['#array_parents'];
return NestedArray::getValue($form, array_slice($parents, 0, -4)); $form_layers = count([
"sources",
"(delta)",
"_remove",
"dropdown_actions",
]);
return NestedArray::getValue($form, array_slice($parents, 0, -$form_layers));
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment