Code Duplication    Length = 6-8 lines in 2 locations

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

@@ 266-273 (lines=8) @@
263
    if ($is_relevant_submit) {
264
      // Submit was triggered by hidden "target_id" element when entities were
265
      // added via entity browser.
266
      if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') {
267
        $parents = $trigger['#parents'];
268
      }
269
      // Submit was triggered by one of the "Remove" buttons. We need to walk
270
      // few levels up to read value of "target_id" element.
271
      elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], $this->fieldDefinition->getName() . '_remove_') === 0) {
272
        $parents = array_merge(array_slice($trigger['#parents'], 0, -static::$deleteDepth), ['target_id']);
273
      }
274
275
      if (isset($parents) && $value = $form_state->getValue($parents)) {
276
        $ids = explode(' ', $value);
@@ 360-365 (lines=6) @@
357
    // are added or by one of the "Remove" buttons. Depending on that we need to
358
    // figure out where root of the widget is in the form structure and use this
359
    // information to return correct part of the form.
360
    if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') {
361
      $parents = array_slice($trigger['#array_parents'], 0, -2);
362
    }
363
    elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], '_remove_')) {
364
      $parents = array_slice($trigger['#array_parents'], 0, -static::$deleteDepth);
365
    }
366
367
    return NestedArray::getValue($form, $parents);
368
  }