Code Duplication    Length = 6-8 lines in 2 locations

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

@@ 279-286 (lines=8) @@
276
    if ($is_relevant_submit) {
277
      // Submit was triggered by hidden "target_id" element when entities were
278
      // added via entity browser.
279
      if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') {
280
        $parents = $trigger['#parents'];
281
      }
282
      // Submit was triggered by one of the "Remove" buttons. We need to walk
283
      // few levels up to read value of "target_id" element.
284
      elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], $this->fieldDefinition->getName() . '_remove_') === 0) {
285
        $parents = array_merge(array_slice($trigger['#parents'], 0, -static::$deleteDepth), ['target_id']);
286
      }
287
288
      if (isset($parents) && $value = $form_state->getValue($parents)) {
289
        $ids = explode(' ', $value);
@@ 398-403 (lines=6) @@
395
    // are added or by one of the "Remove" buttons. Depending on that we need to
396
    // figure out where root of the widget is in the form structure and use this
397
    // information to return correct part of the form.
398
    if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') {
399
      $parents = array_slice($trigger['#array_parents'], 0, -1);
400
    }
401
    elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], '_remove_')) {
402
      $parents = array_slice($trigger['#array_parents'], 0, -static::$deleteDepth);
403
    }
404
405
    return NestedArray::getValue($form, $parents);
406
  }