@@ 137-151 (lines=15) @@ | ||
134 | /** |
|
135 | * AJAX form callback. |
|
136 | */ |
|
137 | public static function updateWidgetCallback(array &$form, FormStateInterface $form_state) { |
|
138 | $trigger = $form_state->getTriggeringElement(); |
|
139 | // AJAX requests can be triggered by hidden "target_id" element when entities |
|
140 | // are added or by one of the "Remove" buttons. Depending on that we need to |
|
141 | // figure out where root of the widget is in the form structure and use this |
|
142 | // information to return correct part of the form. |
|
143 | if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_selected_updated') { |
|
144 | $parents = array_slice($trigger['#array_parents'], 0, -2); |
|
145 | } |
|
146 | elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], '_remove_')) { |
|
147 | $parents = array_slice($trigger['#array_parents'], 0, -4); |
|
148 | } |
|
149 | ||
150 | return NestedArray::getValue($form, $parents); |
|
151 | } |
|
152 | ||
153 | /** |
|
154 | * {@inheritdoc} |
@@ 357-371 (lines=15) @@ | ||
354 | /** |
|
355 | * AJAX form callback. |
|
356 | */ |
|
357 | public static function updateWidgetCallback(array &$form, FormStateInterface $form_state) { |
|
358 | $trigger = $form_state->getTriggeringElement(); |
|
359 | // AJAX requests can be triggered by hidden "target_id" element when entities |
|
360 | // are added or by one of the "Remove" buttons. Depending on that we need to |
|
361 | // figure out where root of the widget is in the form structure and use this |
|
362 | // information to return correct part of the form. |
|
363 | if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') { |
|
364 | $parents = array_slice($trigger['#array_parents'], 0, -1); |
|
365 | } |
|
366 | elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], '_remove_')) { |
|
367 | $parents = array_slice($trigger['#array_parents'], 0, -static::$deleteDepth); |
|
368 | } |
|
369 | ||
370 | return NestedArray::getValue($form, $parents); |
|
371 | } |
|
372 | ||
373 | /** |
|
374 | * Submit callback for remove buttons. |