diff --git a/modules/entity_form/entity_browser_entity_form.module b/modules/entity_form/entity_browser_entity_form.module index 7923680..73696ea 100644 --- a/modules/entity_form/entity_browser_entity_form.module +++ b/modules/entity_form/entity_browser_entity_form.module @@ -42,6 +42,7 @@ function entity_browser_entity_form_inline_entity_form_reference_form_alter(&$re $reference_form['entity_browser'] = [ '#type' => 'entity_browser', '#entity_browser' => $entity_browser_id, + '#cardinality' => $instance->getFieldStorageDefinition()->get('cardinality'), ]; $reference_form['#attached']['library'][] = 'entity_browser_entity_form/ief_autocomplete'; $reference_form['actions']['ief_reference_save']['#ajax']['event'] = 'entities-selected'; diff --git a/src/Element/EntityBrowserElement.php b/src/Element/EntityBrowserElement.php index 1c15de0..00840aa 100644 --- a/src/Element/EntityBrowserElement.php +++ b/src/Element/EntityBrowserElement.php @@ -3,7 +3,6 @@ namespace Drupal\entity_browser\Element; use Drupal\Component\Utility\Html; -use Drupal\Core\Entity\EntityFormInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element\FormElement; use Drupal\entity_browser\Entity\EntityBrowser; @@ -142,19 +141,6 @@ class EntityBrowserElement extends FormElement { $entity_browser = $element['#entity_browser']; } - // Propagate the field cardinality to the EntityBrowser element, if needed. - $form_object = $form_state->getFormObject(); - if ($form_object instanceof EntityFormInterface) { - /** @var EntityInterface $entity */ - $entity = $form_state->getFormObject()->getEntity(); - $bundle = $form_state->get(['form_display'])->get('bundle'); - $field_name = $element['#parents'][0]; - $bundle_fields = \Drupal::getContainer()->get('entity_field.manager')->getFieldDefinitions($entity->getEntityTypeId(), $bundle); - /** @var \Drupal\field\FieldConfigInterface $instance */ - $instance = $bundle_fields[$field_name]; - $element['#cardinality'] = $instance->getFieldStorageDefinition()->get('cardinality'); - } - // Propagate selection if edit selection mode is used. $entity_browser_preselected_entities = []; if ($element['#selection_mode'] === static::SELECTION_MODE_EDIT) {