Code Duplication    Length = 6-8 lines in 2 locations

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

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