Skip to content
This repository has been archived by the owner on Jan 5, 2018. It is now read-only.

2897622 - IEF integration is broken for bundleless entities, base fields and unsaved form displays #156

Open
wants to merge 1 commit into
base: 8.x-1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions modules/entity_form/entity_browser_entity_form.module
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,29 @@ function entity_browser_entity_form_inline_entity_form_reference_form_alter(&$re
'instance',
]);

$entity_form_display_storage = \Drupal::entityTypeManager()->getStorage('entity_form_display');
$target_entity_type_id = $instance->getTargetEntityTypeId();
$target_bundle = $instance->getTargetBundle() ?: $target_entity_type_id;

/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
$entity_form_id = $instance->getTargetEntityTypeId() . '.' . $instance->getTargetBundle() . '.default';
$entity_form_id = $target_entity_type_id . '.' . $target_bundle . '.default';
// TODO - 'default' might become configurable or something else in the future.
// See https://www.drupal.org/node/2510274
$form_display = \Drupal::entityTypeManager()->getStorage('entity_form_display')->load($entity_form_id);
$form_display = $entity_form_display_storage->load($entity_form_id);

// If not found, create a fresh entity object. We do not preemptively create
// new entity form display configuration entries for each existing entity type
// and bundle whenever a new form mode becomes available. Instead,
// configuration entries are only created when an entity form display is
// explicitly configured and saved.
if (!$form_display) {
$form_display = $entity_form_display_storage->create(array(
'targetEntityType' => $target_entity_type_id,
'bundle' => $target_bundle,
'mode' => 'default',
'status' => TRUE,
));
}

$widget = $form_display->getRenderer($instance->getName());

Expand All @@ -47,8 +65,8 @@ function entity_browser_entity_form_inline_entity_form_reference_form_alter(&$re
]));

$cardinality = FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED;
if($instance->getFieldStorageDefinition()->get('cardinality') !== $cardinality) {
$cardinality = $instance->getFieldStorageDefinition()->get('cardinality') - $count_existing_selection;
if ($instance->getFieldStorageDefinition()->getCardinality() !== $cardinality) {
$cardinality = $instance->getFieldStorageDefinition()->getCardinality() - $count_existing_selection;
}

unset($reference_form['entity_id']);
Expand Down