Code Duplication    Length = 6-8 lines in 2 locations

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

@@ 276-283 (lines=8) @@
273
    if ($is_relevant_submit) {
274
      // Submit was triggered by hidden "target_id" element when entities were
275
      // added via entity browser.
276
      if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') {
277
        $parents = $trigger['#parents'];
278
      }
279
      // Submit was triggered by one of the "Remove" buttons. We need to walk
280
      // few levels up to read value of "target_id" element.
281
      elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], $this->fieldDefinition->getName() . '_remove_') === 0) {
282
        $parents = array_merge(array_slice($trigger['#parents'], 0, -static::$deleteDepth), ['target_id']);
283
      }
284
285
      if (isset($parents) && $value = $form_state->getValue($parents)) {
286
        $ids = explode(' ', $value);
@@ 375-380 (lines=6) @@
372
    // are added or by one of the "Remove" buttons. Depending on that we need to
373
    // figure out where root of the widget is in the form structure and use this
374
    // information to return correct part of the form.
375
    if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') {
376
      $parents = array_slice($trigger['#array_parents'], 0, -1);
377
    }
378
    elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], '_remove_')) {
379
      $parents = array_slice($trigger['#array_parents'], 0, -static::$deleteDepth);
380
    }
381
382
    return NestedArray::getValue($form, $parents);
383
  }