| @@ 117-131 (lines=15) @@ | ||
| 114 | /** |
|
| 115 | * AJAX form callback. |
|
| 116 | */ |
|
| 117 | public static function updateWidgetCallback(array &$form, FormStateInterface $form_state) { |
|
| 118 | $trigger = $form_state->getTriggeringElement(); |
|
| 119 | // AJAX requests can be triggered by hidden "target_id" element when entities |
|
| 120 | // are added or by one of the "Remove" buttons. Depending on that we need to |
|
| 121 | // figure out where root of the widget is in the form structure and use this |
|
| 122 | // information to return correct part of the form. |
|
| 123 | if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') { |
|
| 124 | $parents = array_slice($trigger['#array_parents'], 0, -2); |
|
| 125 | } |
|
| 126 | elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], '_remove_')) { |
|
| 127 | $parents = array_slice($trigger['#array_parents'], 0, -4); |
|
| 128 | } |
|
| 129 | ||
| 130 | return NestedArray::getValue($form, $parents); |
|
| 131 | } |
|
| 132 | } |
|
| 133 | ||
| @@ 326-340 (lines=15) @@ | ||
| 323 | /** |
|
| 324 | * AJAX form callback. |
|
| 325 | */ |
|
| 326 | public static function updateWidgetCallback(array &$form, FormStateInterface $form_state) { |
|
| 327 | $trigger = $form_state->getTriggeringElement(); |
|
| 328 | // AJAX requests can be triggered by hidden "target_id" element when entities |
|
| 329 | // are added or by one of the "Remove" buttons. Depending on that we need to |
|
| 330 | // figure out where root of the widget is in the form structure and use this |
|
| 331 | // information to return correct part of the form. |
|
| 332 | if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') { |
|
| 333 | $parents = array_slice($trigger['#array_parents'], 0, -2); |
|
| 334 | } |
|
| 335 | elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], '_remove_')) { |
|
| 336 | $parents = array_slice($trigger['#array_parents'], 0, -4); |
|
| 337 | } |
|
| 338 | ||
| 339 | return NestedArray::getValue($form, $parents); |
|
| 340 | } |
|
| 341 | ||
| 342 | /** |
|
| 343 | * Submit callback for remove buttons. |
|