Code Duplication    Length = 6-8 lines in 2 locations

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

@@ 305-312 (lines=8) @@
302
    if ($is_relevant_submit) {
303
      // Submit was triggered by hidden "target_id" element when entities were
304
      // added via entity browser.
305
      if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') {
306
        $parents = $trigger['#parents'];
307
      }
308
      // Submit was triggered by one of the "Remove" buttons. We need to walk
309
      // few levels up to read value of "target_id" element.
310
      elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], $this->fieldDefinition->getName() . '_remove_') === 0) {
311
        $parents = array_merge(array_slice($trigger['#parents'], 0, -static::$deleteDepth), ['target_id']);
312
      }
313
314
      if (isset($parents) && $value = $form_state->getValue($parents)) {
315
        $entities = EntityBrowserElement::processEntityIds($value);
@@ 454-459 (lines=6) @@
451
    // entities are added or by one of the "Remove" buttons. Depending on that
452
    // we need to figure out where root of the widget is in the form structure
453
    // and use this information to return correct part of the form.
454
    if (!empty($trigger['#ajax']['event']) && $trigger['#ajax']['event'] == 'entity_browser_value_updated') {
455
      $parents = array_slice($trigger['#array_parents'], 0, -1);
456
    }
457
    elseif ($trigger['#type'] == 'submit' && strpos($trigger['#name'], '_remove_')) {
458
      $parents = array_slice($trigger['#array_parents'], 0, -static::$deleteDepth);
459
    }
460
461
    return NestedArray::getValue($form, $parents);
462
  }