Code Duplication    Length = 6-8 lines in 2 locations

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

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