Code Duplication    Length = 6-8 lines in 2 locations

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

@@ 214-221 (lines=8) @@
211
    if (($trigger = $form_state->getTriggeringElement()) && in_array($this->fieldDefinition->getName(), $trigger['#parents'])) {
212
      // Submit was triggered by hidden "target_id" element when entities were
213
      // added via entity browser.
214
      if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') {
215
        $parents = $trigger['#parents'];
216
      }
217
      // Submit was triggered by one of the "Remove" buttons. We need to walk
218
      // few levels up to read value of "target_id" element.
219
      elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], $this->fieldDefinition->getName() . '_remove_') === 0) {
220
        $parents = array_merge(array_slice($trigger['#parents'], 0, -4), ['target_id']);
221
      }
222
223
      if (isset($parents) && $value = $form_state->getValue($parents)) {
224
        $ids = explode(' ', $value);
@@ 344-349 (lines=6) @@
341
    // are added or by one of the "Remove" buttons. Depending on that we need to
342
    // figure out where root of the widget is in the form structure and use this
343
    // information to return correct part of the form.
344
    if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') {
345
      $parents = array_slice($trigger['#array_parents'], 0, -2);
346
    }
347
    elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], '_remove_')) {
348
      $parents = array_slice($trigger['#array_parents'], 0, -4);
349
    }
350
351
    return NestedArray::getValue($form, $parents);
352
  }