/**
  * {@inheritdoc}
  */
 protected function formMultipleElements(FieldItemListInterface $items, array &$form, FormStateInterface $form_state)
 {
     $element = parent::formMultipleElements($items, $form, $form_state);
     // If we're using ulimited cardinality we don't display one empty item. Form
     // validation will kick in if left empty which esentially means people won't
     // be able to submit w/o creating another entity.
     if (!$form_state->isSubmitted() && $element['#cardinality'] == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED && $element['#max_delta'] > 0) {
         $max = $element['#max_delta'];
         unset($element[$max]);
         $element['#max_delta'] = $max - 1;
         $items->removeItem($max);
         // Decrement the items count.
         $field_name = $element['#field_name'];
         $parents = $element[0]['#field_parents'];
         $field_state = static::getWidgetState($parents, $field_name, $form_state);
         $field_state['items_count']--;
         static::setWidgetState($parents, $field_name, $form_state, $field_state);
     }
     // Remove add options if the user cannot add new entities.
     if (!$this->canAddNew()) {
         if (isset($element['add_more'])) {
             unset($element['add_more']);
         }
         foreach (Element::children($element) as $delta) {
             if (isset($element[$delta]['inline_entity_form'])) {
                 if ($element[$delta]['inline_entity_form']['#op'] == 'add') {
                     unset($element[$delta]);
                 }
             }
         }
     }
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 protected function formMultipleElements(FieldItemListInterface $items, array &$form, FormStateInterface $form_state)
 {
     $element = parent::formMultipleElements($items, $form, $form_state);
     // If we're using ulimited cardinality we don't display one empty item. Form
     // validation will kick in if left empty which esentially means people won't
     // be able to submit w/o creating another entity.
     if ($element['#cardinality'] == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED && $element['#max_delta'] > 0) {
         $max = $element['#max_delta'];
         unset($element[$max]);
         $element['#max_delta'] = $max - 1;
         $items->removeItem($max);
     }
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public function settingsSummary()
 {
     $summary = parent::settingsSummary();
     $labels = $this->labels();
     if ($this->getSetting('allow_new')) {
         $summary[] = $this->t('New @label can be added.', ['@label' => $labels['plural']]);
     } else {
         $summary[] = $this->t('New @label can not be created.', ['@label' => $labels['plural']]);
     }
     $match_operator_options = $this->getMatchOperatorOptions();
     if ($this->getSetting('allow_existing')) {
         $summary[] = $this->t('Existing @label can be referenced and are matched with the %operator operator.', ['@label' => $labels['plural'], '%operator' => $match_operator_options[$this->getSetting('match_operator')]]);
     } else {
         $summary[] = $this->t('Existing @label can not be referenced.', ['@label' => $labels['plural']]);
     }
     return $summary;
 }