Code Duplication    Length = 6-8 lines in 2 locations

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

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