/**
  * {@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;
 }