Code Duplication    Length = 6-8 lines in 2 locations

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

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