Problem/Motivation

Follow up from #2412569: Allow setting the auto-create bundle on entity reference fields with multiple target bundles and #2712545: Field setting form is broken after 2412569. Bug priority is set as per the core issue.

Steps to reproduce

TBD

Proposed resolution

Copy the \Drupal\Core\Field\Plugin\Field\FieldWidget\EntityReferenceAutocompleteWidget::getAutocreateBundle() logic into \Drupal\dynamic_entity_reference\Plugin\Field\FieldWidget\DynamicEntityReferenceWidget::getAutocreateBundle()

Remaining tasks

User interface changes

UI triggers warning if there is no 'auto_create_bundle'.

API changes

None.

Data model changes

None

Comments

jibran created an issue. See original summary.

jibran’s picture

Status: Active » Needs review
StatusFileSize
new2.21 KB
larowlan’s picture

Status: Needs review » Needs work
+++ b/src/Plugin/Field/FieldWidget/DynamicEntityReferenceWidget.php
@@ -224,17 +224,26 @@ class DynamicEntityReferenceWidget extends EntityReferenceAutocompleteWidget {
+        $bundle = $target_type;
...
+      elseif (count($target_bundles) == 1) {
         $bundle = reset($target_bundles);
...
+      elseif (!$bundle = $this->getSelectionHandlerSetting('auto_create_bundle', $target_type)) {

let's return early here and avoid both the elseifs

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new1.72 KB
new2.37 KB
jibran’s picture

StatusFileSize
new1.76 KB
new2.36 KB

Thanks for the review addressed #3.

larowlan’s picture

Status: Needs review » Reviewed & tested by the community
larowlan’s picture

Nice work

  • jibran committed 32f105d on 8.x-2.x
    Issue #3249333 by jibran, larowlan: Allow setting the auto-create bundle...

  • jibran committed e203b6b on 8.x-1.x
    Issue #3249333 by jibran, larowlan: Allow setting the auto-create bundle...
jibran’s picture

Status: Reviewed & tested by the community » Fixed

Thank you. Committed and pushed to both 2.x and 1.x.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.