Code Duplication    Length = 6-8 lines in 2 locations

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

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