Code Duplication    Length = 6-8 lines in 2 locations

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

@@ 315-322 (lines=8) @@
312
    if ($is_relevant_submit) {
313
      // Submit was triggered by hidden "target_id" element when entities were
314
      // added via entity browser.
315
      if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') {
316
        $parents = $trigger['#parents'];
317
      }
318
      // Submit was triggered by one of the "Remove" buttons. We need to walk
319
      // few levels up to read value of "target_id" element.
320
      elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], $this->fieldDefinition->getName() . '_remove_') === 0) {
321
        $parents = array_merge(array_slice($trigger['#parents'], 0, -static::$deleteDepth), ['target_id']);
322
      }
323
324
      if (isset($parents) && $value = $form_state->getValue($parents)) {
325
        $ids = explode(' ', $value);
@@ 427-432 (lines=6) @@
424
    // are added or by one of the "Remove" buttons. Depending on that we need to
425
    // figure out where root of the widget is in the form structure and use this
426
    // information to return correct part of the form.
427
    if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') {
428
      $parents = array_slice($trigger['#array_parents'], 0, -1);
429
    }
430
    elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], '_remove_')) {
431
      $parents = array_slice($trigger['#array_parents'], 0, -static::$deleteDepth);
432
    }
433
434
    return NestedArray::getValue($form, $parents);
435
  }