Code Duplication    Length = 6-8 lines in 2 locations

src/Plugin/Field/FieldWidget/EntityReference.php 2 locations

@@ 222-229 (lines=8) @@
219
    if (($trigger = $form_state->getTriggeringElement()) && in_array($this->fieldDefinition->getName(), $trigger['#parents'])) {
220
      // Submit was triggered by hidden "target_id" element when entities were
221
      // added via entity browser.
222
      if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') {
223
        $parents = $trigger['#parents'];
224
      }
225
      // Submit was triggered by one of the "Remove" buttons. We need to walk
226
      // few levels up to read value of "target_id" element.
227
      elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], $this->fieldDefinition->getName() . '_remove_') === 0) {
228
        $parents = array_merge(array_slice($trigger['#parents'], 0, -4), ['target_id']);
229
      }
230
231
      if (isset($parents) && $value = $form_state->getValue($parents)) {
232
        $ids = explode(' ', $value);
@@ 352-357 (lines=6) @@
349
    // are added or by one of the "Remove" buttons. Depending on that we need to
350
    // figure out where root of the widget is in the form structure and use this
351
    // information to return correct part of the form.
352
    if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') {
353
      $parents = array_slice($trigger['#array_parents'], 0, -2);
354
    }
355
    elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], '_remove_')) {
356
      $parents = array_slice($trigger['#array_parents'], 0, -4);
357
    }
358
359
    return NestedArray::getValue($form, $parents);
360
  }