Code Duplication    Length = 6-8 lines in 2 locations

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

@@ 298-305 (lines=8) @@
295
    if ($is_relevant_submit) {
296
      // Submit was triggered by hidden "target_id" element when entities were
297
      // added via entity browser.
298
      if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') {
299
        $parents = $trigger['#parents'];
300
      }
301
      // Submit was triggered by one of the "Remove" buttons. We need to walk
302
      // few levels up to read value of "target_id" element.
303
      elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], $this->fieldDefinition->getName() . '_remove_') === 0) {
304
        $parents = array_merge(array_slice($trigger['#parents'], 0, -static::$deleteDepth), ['target_id']);
305
      }
306
307
      if (isset($parents) && $value = $form_state->getValue($parents)) {
308
        $ids = explode(' ', $value);
@@ 410-415 (lines=6) @@
407
    // are added or by one of the "Remove" buttons. Depending on that we need to
408
    // figure out where root of the widget is in the form structure and use this
409
    // information to return correct part of the form.
410
    if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') {
411
      $parents = array_slice($trigger['#array_parents'], 0, -1);
412
    }
413
    elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], '_remove_')) {
414
      $parents = array_slice($trigger['#array_parents'], 0, -static::$deleteDepth);
415
    }
416
417
    return NestedArray::getValue($form, $parents);
418
  }