Problem/Motivation
If an Entity Reference field references one bundle, the checkbox "Create referenced entities if they don't already exist" is checked, and an "Autocomplete" widget is chosen, then users can create new entities for that bundle by simply typing in a new label into the text field. However if more then one bundle is referenced, then no entities are added.
Proposed resolution
Move the auto_create setting into EntityReferenceAutocompleteWidget widget settings because the widget should be in business of doing "auto-create".
In widget settings, let the site builder choose a target bundle where the auto-created entities to be stored when the entity reference field is configured to use more than one bundle as destination and auto-creation of entities is enabled.
Remaining tasks
None.
User interface changes
On the field config page: /admin/structure/types/manage/article/fields/{entity}.{bundle}.{field}
Only one vocabulary as destination

Two vocabularies as destination but no auto-creation

Two vocabularies as destination with auto-creation

JavaScript disabled

API changes
Remove auto_create setting from selection handler settings. Two new widget settings: auto_create and auto_create_bundle for EntityReferenceAutocompleteWidget widgets.
Beta phase evaluation
| Issue category | Bug because it breaks a functionality: entity auto-creation. |
|---|---|
| Issue priority | Major because the entity auto-creation doesn't work when multiple bundles are selected as target |
| Disruption | Disruption handled by hook_update_N() implementation. |
| Comment | File | Size | Author |
|---|---|---|---|
| #167 | interdiff.txt | 4.81 KB | amateescu |
| #167 | 2412569-167.patch | 30.94 KB | amateescu |
| #156 | interdiff.txt | 3.69 KB | amateescu |
| #156 | 2412569-156.patch | 30.99 KB | amateescu |
| #150 | interdiff.txt | 843 bytes | amateescu |
Comments
Comment #1
ifrikComment #2
jibranIs it still an issue after #1959806: Provide a generic 'entity_autocomplete' Form API element.
Comment #3
amateescu commentedYup, that issue had nothing to do with this bug.
Comment #4
jhedstromComment #5
claudiu.cristeaPatch.
Please credit @amateescu because he guided me in this issue.
Comment #6
amateescu commentedGreat work on the patch and the screenshots, thanks a lot @claudiu.cristea! I just found a few small things to complain about:
Let's remove these changes and let #2452957: Remove node & taxonomy term hardcoding of bundle names in SelectionBase deal with them.
filed -> field :)
We should use the array() syntax here because it looks a bit weird when all the code around it is not converted to the [] syntax.
Comment #7
claudiu.cristeaI preferred to convert the rest of arrays in
[]format because it doesn't increase the foot print too much.Comment #8
amateescu commentedSure, converting the rest of them to the [] syntax is also fine. I reviewed the patch once more and found a few other things to fix. Sorry for not catching them in the first review, I was just on my out of the room :/
We need to put some information about when that exception is thrown, in this case we can copy some parts of the comment just above it. Something like: "Thrown when the 'auto_create' and 'auto_create_bundle' settings are inconsistent."
Even though we expose this setting only on taxonomy term references for now, the setting is still generic so it should mention 'Bundle' instead of 'Vocabulary' -> "Bundle where auto-created entities are stored."
Really minor: 'select' -> 'selected' :)
How about "Enable the second vocabulary as a target bundle."?
Comment #9
claudiu.cristeaThank you for review.
Comment #10
amateescu commentedRerolled after #2452957: Remove node & taxonomy term hardcoding of bundle names in SelectionBase. The patch looks great now :)
Comment #12
amateescu commentedThat reroll was missing the schema addition, fixed it.
Comment #13
yched commentedSeems wrong to talk about "vocabularies" in the generic ERAutocompleteWidget ?
Wondering: what's the reason why it is only TermSelection that can provide a UI for that otherwise generic (described in the generic entity_reference_selection config schema and used by the generic AutocompleteWidget) setting ?
Comment #14
claudiu.cristea@yched,
I fully agree and I can move that in the generic level but I found this line (see the @todo) in
TermSelection.phpand I thought that maybe there are other reasons for limiting only to taxonomy term.Maybe @amateescu knows better why?
Comment #15
claudiu.cristea@yched, @amateescu,
I expanded the auto-creation to all target entities. At least the manually testing was OK, let's see the bot.
Any comments on expanding the auto-creation capability to all types?
Comment #17
claudiu.cristeaSorry! Interdiff still against #14 and comment from #15.
Comment #18
claudiu.cristeaChange the title accordingly.
Comment #19
claudiu.cristeaSmall fix in setting a default.
Comment #20
amateescu commentedThe only reason for restricting the 'autocreate' feature to taxonomy terms in the UI is that entity API was not in a very good shape at the time (read: mostly broken), so we wanted to have as few things that could break as possible :)
Expanding it to all entity types now seems like a good idea to me as well.
Comment #21
alexpottThis is not tested. Originally I though that would never occur. But I think it can so let's test it.
Comment #22
yched commentedLast nitpick while we're in there :
Havinga validate callback that just ditches some of the submitted values looks a bit surprising. I'm sure there's a reason, but it might be worth a comment ?
Comment #23
amateescu commentedThe reason is that we don't that value to end up in config :P
Comment #24
claudiu.cristeaAdded/changed:
\Drupal\entity_reference\Tests\EntityReferenceTestTrait.Comment #25
jibranThis key is confusing i thought it means we are auto creating bundles, why would we do that? So maybe bundle_of_auto_create.
Comment #26
amateescu commentedIf we're going to change that, I would prefer
bundle_for_auto_create, but I also think the current name is fine :) Other opinions? :)Comment #27
claudiu.cristea@jibran, It might be confusing if you read it as a phrase but it's not in the logic of field config settings. In fact the key name is
bundlebut is namespaced withauto_create_*because is someting that belongs to that setting. Withoutauto_createON the setting doesn't make sense. By this naming I wanted to tell thatauto_create_bundleis dependant onauto_create. Read it as The bundle where we save when auto creating. I was tempted to add aauto_create_settingsas array having a simplebundlekey exactly ashandlerandhandler_settingsis doing. But that would bring an unnecessary level if nesting.@amateescu, I addressed all points raised by @yched and @alexpott. If we can live with the new setting naming let's RTBC this :)
Comment #28
amateescu commentedAgreed, let's do that.
Comment #29
yched commentedNo strong opinion on the setting name. I see how the current name could be misleading, not sure it's worth losing the 'auto_create_' prefix pattern. So, the current works for me.
Minor :
A bit approximative; striclty speaking, bundles are not storage locations. "Bundle assigned to the auto-created entities" ?
Can be fixed anytime in a quick followup if needed, so keeping at RTBC
Comment #30
amateescu commentedThanks, @yched! Let's avoid a "needs work" cycle for that :)
Comment #31
amateescu commented@xjm pointed out in #1847596-267: Remove Taxonomy term reference field in favor of Entity reference that
taxonomy_help()says:but the last part of the sentence is not true anymore after this patch, so we need to update it. I vote for simply removing that part because the UI is pretty straightforward in letting users know that they need to choose the target bundle in which to place auto-created entities.
Comment #32
alexpottWe could also change the config structure to
Which, in my opinion, is much clearer. However this is more of an API break. Setting to needs review to get feedback on this suggestion.
And wow is the entity reference field UI confusing. If you select "Taxonomy term" you don't get to choose the autocreate settings... you just get to limit it to a particular bundle. You have to choose "Other..." to be able to set this. Is there an issue to address this?
Comment #33
amateescu commentedI don't have any preference on the current config structure vs. the one proposed in #32. The nice thing about the current patch is that it's only an API addition though.
Yes, #1847596: Remove Taxonomy term reference field in favor of Entity reference will fix that :)
Comment #34
claudiu.cristeaI'm fine with this.
Comment #35
amateescu commentedI'm not sure about this... the interdiff looks mostly ok but I still think it's not really worth the API break, so I'm +1 to #31 and just "fine.. if everyone else wants it that much" on #34 :)
Comment #36
yched commentedSame as #35 :-)
Comment #37
alexpottOkay as I wrote in #32 - we should discuss it. I agree that not breaking the API is probably the way to go here. Unfortunately this patch needs a reroll. So lets reroll #31.
Also we need to add a dependency on the bundle if it is a config entity.
Comment #38
alexpottRe the dependency part of #37 - what happens atm if a bundle is deleted and it is used for auto create?
Comment #39
siva_epari commentedPatch from #31 rerolled.
Comment #40
amateescu commentedTesting the patch first.
Comment #41
claudiu.cristea@alexpott, Let's handle that in #1978714: Entity reference doesn't update its field settings when referenced entity bundles are deleted.
Comment #42
amateescu commentedI opened #2458337: Add missing config dependencies for the entity reference field type to tackle all the missing dependencies.
Re #38: We can handle that in #1978714: Entity reference doesn't update its field settings when referenced entity bundles are deleted.
Comment #43
claudiu.cristea@amateescu, I don't see the reason for 2 issues handling the same thing: sync field config settings when target bundles are removed/renamed.
Comment #44
amateescu commented@claudiu.cristea, you might want to read #42 again, I'm talking about two different things there :P
Comment #45
alexpottI'm not sure I agree with #42 - this issue is adding a new bundle containing field. Let's not fix a bug and create more known bugs at the same time.
Comment #46
amateescu commented@alexpott, the known bugs are already there, we need to add dependencies on:
- the target bundles
- the target entity type
- the sort field
- the filter (roles) field for users
This one is just one more to add to the list and I think it will be easier if we handle all of then in one issue/patch.
Comment #47
amateescu commentedDiscussed in IRC with @alexpott and we agreed that we should fix the dependency problem here.
Basically, we need to implement some self-healing in
EntityReferenceItem::onDependencyRemoval()by completely disabling 'auto_create' if the bundle specified in 'auto_create_bundle' is deleted.Comment #48
amateescu commented@claudiu.cristea, let me explain #44 a bit more:
The difference between #1978714: Entity reference doesn't update its field settings when referenced entity bundles are deleted and #2458337: Add missing config dependencies for the entity reference field type is that the first issue is about updating the field definition (i.e. its settings) when a bundle is renamed or deleted, while the second one is about adding all the missing config dependencies (i.e. not just bundles) and probably implement some self-healing like we'll be adding here.
If you think the difference is too subtle to split in two separate issues, I'm fine with merging them in #1978714: Entity reference doesn't update its field settings when referenced entity bundles are deleted.
Comment #49
claudiu.cristeaComment #50
amateescu commentedWe need to check if our 'auto_create_bundle' is in the $dependencies array, not just delete the setting unconditionally :)
Comment #51
claudiu.cristeaVoilà!
Comment #52
amateescu commentedWe also need to check if the target entity types uses config entities for its bundles, because that's not always the case.
Also, getBundleEntityType() currently returns a bogus 'bundle' value by default instead of NULL, so we should probably postpone this on #2346857: Set default property bundle_entity_type in EntityType to NULL in order to not introduce even more special casing for the crappy current return value.
Comment #53
claudiu.cristeaPostponed on #2346857: Set default property bundle_entity_type in EntityType to NULL.
Comment #54
andypostComment #55
jibran#2346857: Set default property bundle_entity_type in EntityType to NULL just landed.
Comment #57
claudiu.cristeaWait, wait... this needs some additional work not just a reroll.
Comment #59
claudiu.cristea@amateescu, added the check requested in #52.
Comment #60
amateescu commentedThe entity reference field cannot be configured to store new entities in multiple bundles, it can just reference entities from multiple bundles.
How about: Thrown when the field allows references from multiple target bundles, 'auto_create' is enabled and 'auto_create_bundle' is not set.
This exception message is not really friendly as it assumes that the user knows how ER stores its settings internally.
How about something like:
The 'Create referenced entities if they don\'t already exist' option is enabled but a specific destination bundle is not set. You should re-visit and fix the settings of the $field_name field.
Of course, $field_name needs to be replaced with the actual field name :)
The isset() check is not correct, it should be an in_array() check instead.
Also, we can provide a better fallback in the case when the bundle specified in 'auto_create_bundle' was removed and the field now allows only one target bundle, we can default to that.
Since we moved the 'auto_create' form element in the parent class, we should remove it from the Term-specific one.
Unrelated change.
This change should be reverted as well, the current text is more accurate :)
Comment #61
claudiu.cristea@amateescu, thank you!
Thinking more on this. We must resolve also the cleanup of the handler settings
target_bundleshere, not in #1978714: Entity reference doesn't update its field settings when referenced entity bundles are deleted. We'll leave only the renaming for #1978714: Entity reference doesn't update its field settings when referenced entity bundles are deleted.Let me know what you think.
Comment #62
amateescu commentedNot sure about that, this patch is well contained and fixes a bug on its own.
Comment #64
yched commentedComing to think of it, it seems 'auto_create_bundle' should be a setting of the autocomplete widget ?
API-wise, an ER field supports assigning an unsaved (but otherwise *fully formed*) $entity in $item->entity, and saving it along as the field is saved. No need for an 'auto_create_bundle' for that, the $entity has a bundle.
It's only the autocomplete widget that, on top of that, lets you create an $entity to reference out of a mere label string, and thus needs to know which bundle to assign it. Another widget (there are some in contrib D7 IIRC) could additionally show a dropdown to let you pick the bundle of the newly created entiy, and wouldn't need an 'auto_create_bundle'.
In fact, strictly speaking, what the ER field type supports is "auto-save", it's the autocomplete widget that does "auto-create".
Thoughts ?
Comment #65
amateescu commented@yched, the line of thought in #64 is correct. So you would prefer if we move both the existing 'auto_create' and the new 'auto_create_bundle' settings to the widget(s) in this patch?
Edit: also, we'd need to check if that would be a usability regression :/
Comment #66
claudiu.cristea#60.1, 2, 4, 5, 6: Done.
#60.3: This requirement is hard to implement without #61 because I need to count the target bundles. So, they both belong to this piece of code and we should treat them in the same move.
EDIT: I fully agree with you that somehow this is not part of this issue but...
EDIT2:
I checked this twice,
in_array()doesn't work here. I wrote a test for dependency stuff that should prove :)Comment #67
yched commentedHm, right, they go hand in hand (logically, and in the UI through #states).
Well, I guess #64 could also be said about 'auto_create', it's the autocomplete widget that can be configured to auto-create or not ? (I mean, that mimicks the properties of the underlying entity_autocomplete FAPI #type, right ?)
I might be missing something, but I doubt there are actual uses of 'auto_create' as part of the selection plugin, I can't really see how that affects the selection process ?
Comment #68
amateescu commentedYup.
Also true, 'auto_create' is a selection plugin setting only for historical reasons.
Comment #69
yched commentedWell, IMO simplifying the "ER field" config form by removing a setting that only makes sense for a specific widget
(that isn't even the default ER widget - hm, BTW, ERItem specifies no default widget ?)[edit: ok, scratch that, e_r.module does make it the default ER widget], and putting in the config screen for that widget only if you select it, is a usability win ;-)Comment #70
claudiu.cristeaBased on #67.
Known issue:
Unfortunately
WidgetInterfacedoesn't implementonDependencyRemoval()so we musthook_entity_bundle_delete()and so, we're back in to the ER field finder from #1978714: Entity reference doesn't update its field settings when referenced entity bundles are deleted. And that cannot be worked now because #2337191: Split up EntityManager into many services is not in. Also all these ER settings update have to implementhook_entity_bundle_delete/rename()but entity_reference.module will go away in #2429191: Deprecate entity_reference.module and move its functionality to core. So...So, I opened #2553169: Dispatch bundle CRUD events to be able to handle all these synchronizations directly in core. Even I agree with #45, my proposal is to not handle now the settings update. Right now this is already broken because "target_bundles" are not updated. We can fix this when:
Opinions?
Comment #71
claudiu.cristeaUpdating issue summary.
Also, I found that we need an update path for
auto_create, from handler settings to widget settings.Comment #73
claudiu.cristeaAdded update path for settings in
system_update_8004(). I avoided the ER module because sooner or latter will be removed.Comment #74
yched commentedNot sure I follow. The new 'auto_create_bundle' is a widget, so what would need an update is the widget settings (i.e the EntityFormDisplay), not the ER field ?
I agree that, since ER currently doesn't update its 'target_bundles' either, it could be OK to leave the 'auto_create_bundle' widget setting dangling as well, and fix both in the same issue if that's easier, but I don't really see
Regarding bundle deletion : well, if the 'auto_create_bundle' setting refers to a bundle, I guess it means the containing config entity (EntityFormDisplay) should have a dependency on that bundle and that bundle shouldn't be removable ?
Well, it's Core that defines both the selection plugins and the autocomplete widget, so putting the update in e_r wouldn't make sense anyway ;-)
Comment #75
claudiu.cristea@yched, thank you! I was a little bit confused about the relation between form display and widgets. Now it makes sense.
Comments:
auto_create_bundlewill be set to NULL and auto creation disabled. An I think this is correct because... (Second), we cannot make an assumption on how the site builder wants to set that field. IMO, we should be consistent here across all the cases. Maybe simply registering a warning log entry telling: "Bundle 'tags' was deleted and the auto-creation for fieldshas been disabled. Reconfigure each field..." (a good message to be find). Opinions?
auto_createandauto_create_bundle, is bit redundant. We can considerauto_create_bundle == NULLas "disabled auto-creation"? I that case we need to treat target entities without bundle (like user) but I don't think that it would be too difficult. What about this?\Drupal\system\Tests\Field\EntityReferenceSettingsTest) is temporary built on the oldKernelTestBasebecause of #2553661: KernelTestBase fails to set up FileCache. When the bug will be fixed I'll convert the test.EDIT: And I think that
system_update_8004() deserves a test...Comment #77
claudiu.cristeaAdded the test for
system_update_8004().Comment #79
claudiu.cristeaHere we go.
Comment #80
claudiu.cristeaHere's patch with a version based on #75.2: Removing the redundancy of having both
auto_create_bundleandauto_create.Pros:
auto_createisTRUEANDauto_create_bundleisNULL.Cons:
Right now, in this patch, there's a small loss of UX by not having that checkbox that makes the interface more meaningful to the user. I can fix that by adding a checkbox with states only to show hide the bundles select element if we go with this solution.
So, @yched, @amateescu, what is your opinion? Should we go with this approach or continue with #79?
Comment #81
jibranOk if I have an autocreate entity autocomplete element in a custom form how can I mention bundle settings there? Because of this I think this helper method should live in
\Drupal\Core\Entity\Element\EntityAutocompleteas a static method to which we can pass target_type and auto_create_bundle setting. What do you think about it?Comment #82
jibranAnd moving this to widget is a good call ++ on that. Some what related widget setting issue for DER is #2381993: Allow view mode or formatter to be selected per item in the widget.
Comment #83
claudiu.cristea@jibran, I'm not sure I understand your question. After quick looking in the code, I guess you'll need to add something like this:
EDIT: Fixed the
#autocreatekey.Comment #84
claudiu.cristeaReroll of #80.
Comment #86
claudiu.cristeaFixed update test.
Comment #88
claudiu.cristeaComment #89
claudiu.cristeaThis is major because the entity auto-creation doesn't work when multiple bundles are selected as target. Added beta evaluation.
Comment #91
claudiu.cristeaComment #92
jibranThis function doesn't belong to this class.
Comment #93
claudiu.cristea@jibran,
Yes, it seems so. But if we'll look closer, we can see that it's just a helper for
calculateDependencies()andonDependencyRemoval(), providing a very customized return structure, not usable in other places. AndcalculateDependencies()andonDependencyRemoval()are part ofEntityFormDisplayinterface. Moving that helper to other class it would not make too much sense. I tried only to reuse code.Comment #94
yched commentedHaving specific code in EntityFormDisplay about ER fields and EntityReferenceAutocompleteWidget does sound like a no-go :-/
This widget happens to have a dependency based on what's present in one of its settings, it should be the widget that exposes that.
On the next widget (or formatter) that has such a case, we don't want to keep adding more specific code in EntityDisplays - and contrib won't be able to do such a thing anyway.
Meaning, EntityDisplayBase::calculateDependencies() should call each widget / formatter and ask for its dependencies - it's weird, I thought we had something like that in place, but apparently we don't.
As was discussed earlier I think, we might argue leaving that for a separate issue, since we already have problems with ER-related settings not updating when a bundle name changes ?
Comment #95
claudiu.cristeaWe can fix this here by iterating through all components and collect dependencies from widgets. Or, better open a new issue just for that to cover also formatters?
I wanted that earlier but @alexpott disagreed in #45. If we go with a new issue for collecting dependencies for widgets/formatters then maybe we can postpone this till fixing that.
Comment #96
yched commentedOuch. Then yes, I guess a new issue postponing this one is the way to go :-/
Comment #97
jibranThanks @yched for the clarity.
Comment #98
claudiu.cristeaPostponing this on #2562107: EntityDisplayBase should react on removal of its components dependencies.
Comment #99
claudiu.cristeaTagging.
Comment #100
claudiu.cristeaDiscussed with @yched and @amateescu at Drupalcon Barcelona to check with core committers if moving the auto_create from filed to widget is feasible in 8.0.x. Assigning to @yched to get a resolution on that.
Comment #101
yched commentedMe and @amateescu discussed this with @alexpott in Barcelona.
@alexpott agrees that moving the setting to the widget is cleaner and makes more sense, and would be acceptable with an update hook if we can get it ready before RC.
However, discussing further with @amateescu, we hit another question with that approach :
The bundle stored in the widget setting needs to be one of the bundles referenceable by the field.
Then, what do we do when someone modifies the field settings and removes the "bundle used for autocreate by the widget" from the list of possible target bundles ?
- We could add a FAPI #validate in the settings form defined by SelectionBase::buildConfigurationForm() so that any bundle currently used for autocreate by any widget in any form mode, cannot be removed from the list of target bundles. @alexpott seemed to agree with that approach.
- Or, keeping the 'autocreate_bundle' setting in the field setting makes it easier to make sure that it never gets inconsistent...
Comment #102
jibranThis seems much better and simple imo.
Comment #103
yched commentedComing from #2064191-47: Fix the 'target_bundle' field setting - 'target_bundles' are not validated when entity_reference is enabled :
Meaning, we should not offer to "autocreate" if the selection handler is ViewsSelector...
Which is another argument for "it's simpler to keep autocreate settings in the same UI than the selection handler". So, fine, let's do that :-)
Comment #104
yched commentedMeaning it can also be unpostponed
Comment #105
claudiu.cristeaI don't get it. Will be on field or widget?
Comment #106
yched commentedSorry, that wasn't clear.
I meant :
[autocreate should not be offered with ViewsSelection handler] is another argument for "it's simpler to keep autocreate settings in the field settings, where the selection settings also are".
So, yeah, let's go with field settings I guess.
Comment #107
amateescu commentedNice that we finally have consensus on where to store the setting :) Here's #66, rerolled, cleaned up a little and also applied on top of #1978714-86: Entity reference doesn't update its field settings when referenced entity bundles are deleted because both issues need the same code to handle the 'target_bundles' config dependency.
Comment #109
jibranIMO we should add a change record for this. Patch looks good let's fix the fails.
Comment #111
amateescu commentedLet's :) I don't think a CR is needed for this patch.
Comment #112
jibranYay!!! green. Looks perfect to me. @yched please nitpick the patch. :D Other then that and parent issue this is ready.
Comment #113
yched commentedNit : we're logging a critical, not a warning :-)
It's really unfortunate that SelectionBase is both a base class and an actual selection plugin with "by bundle" logic that subclasses willing to use the base class then need to undo.
That means any change in the "by bundle" handler, like the one here, can break any other Selection class.
Probably not for this issue to change, though :-/
Also : as mentioned in #2577963: Let entity_ref Selection handlers be in charge of the field validation, ViewsSelector is in fact incompatible with auocreate, since we cannot validate that a newly created entity that is not in the db yet is going to match a given View. Not sure if that means there is additional UI adjustments needed (do not provide the option for ViewsSelection), and if we want to do them here, just saying :-)
I'm not seeing anywhere this button is actually used ? Or is there some automagical ajax wiring with the 'target_bundles' select I have forgotten about ?
Aw - we didn't have any UI controlling that so far ?
If the bundle used for auto_create disappears, do we really want to silently switch a a random other bundle ?
Comment #114
amateescu commentedThanks for reviewing!
Comment #115
yched commented#114.1 : yeah sorry, I started reviewing the "full" patch before I realized it contained the patch for the other issue :-)
#114.2
Well, ViewsSelection does use it as a base class, and then needs to undo the logic in a couple places. Do you think having a real base class and renalming the current SelectionBase to DefaultSelection would break a lot of things ? I guess contrib modules that started adding selection adjustments for their own entity types ?
If not possible, then I guess we could at least make ViewsSelection stop extending it ? But right, probably not for this issue...
Looks ready then - but postponed on #1978714: Entity reference doesn't update its field settings when referenced entity bundles are deleted, right ?
Comment #116
amateescu commentedYes, I should've been more in favor of the trait in #2482705-12: ViewsSelection::validateAutocompleteInput is not implemented, which is the recent issue that made ViewsSelection extend SelectionBase :/ We can definitely open a new issue to clean it up, since it seems that ViewsSelection has to undo more and more things from SelectionBase..
Comment #117
yched commented@amateescu : right, so this is only about reusing SelectionBase::validateAutocompleteInput() ?
Since that code is only called by Element\EntityAutocomplete::validateEntityAutocomplete(), and seems to only contain some generic logic to bridge between Selection::getReferenceableEntities() and the form autocomplete format, maybe it could also be moved directly into EntityAutocomplete::validateEntityAutocomplete() ?
i.e EntityAutocomplete calls Selection::getReferenceableEntities(), which contains the real "selection logic", and then simply massages the results for its own "autocomplete" needs ? SelectionInterface then doesn't have any method about the specific use case of autocomplete ?
Comment #118
yched commentedSubmitted a patch in #2578559: Have ViewsSelection no longer extend SelectionBase :-)
Comment #121
jibranStill postpone on #1978714: Entity reference doesn't update its field settings when referenced entity bundles are deleted.
Comment #122
yched commented#1978714: Entity reference doesn't update its field settings when referenced entity bundles are deleted got in, unpostponing + working on a reroll.
Comment #123
yched commentedReroll was the 2412569-114-do-not-test.patch from #114, with some fuzz.
Comment #124
yched commentedSide note : I virtually RTBCed the 2412569-114-plus-1978714.patch in #115, so I feel I'm fine RTBCing the standalone patch @amateescu had prepared :-)
Comment #125
alexpottNeeds reroll.
Comment #126
amateescu commentedRerolled.
Comment #127
jibran+1 for RTBC
PS: As much as all these ER fixes are awesome and I'm happy that we are almost done with it before RC deadline but DER is extremely broken now :P and I don't know where to start :D
Comment #128
amateescu commentedHappily rerolled again for #2429191: Deprecate entity_reference.module and move its functionality to core :)
Comment #129
claudiu.cristeaRestored screenshots corresponding to the RTBC solution.
Comment #130
claudiu.cristeaComment #131
catchComment #133
amateescu commentedRerolled.
Comment #134
alexpottDiscussed this with @xjm, @catch, and @effulgentsia, and we agreed to make this an RC target but we're not convinced by the solution. We think that we should do the minimal fix which is to remove the auto create option if there are multiple bundles.
Comment #135
xjmI think the minimal fix described in #134 would also be patch-release safe, though the current patch would not be.
Comment #136
claudiu.cristea@xjm, sorry but I cannot understand why a patch that doesn't exist yet is "safe" while the current one, which was heavily commented, reviewed, amended and RTBC-ed is not :)
Comment #137
ifrikI've reviewed patch #133 from a sitebuilder's perspective, and - with JavaScript enabled - it works as desired.
But without JavaScript, the two buttons "Change handler" and "Update bundles" are rather confusing.
1) I don't think we use "bundles" in other places in UI text, so it probably should be reworded.
2) When I tick an additional vocabulary, and then click on "Update bundles" the page gets reloaded and the vocabulary is unticked again. Is that intended behaviour? Or if not, what is that button for?
Comment #138
catch@claudiu.cristea - because the current patch makes changes to configuration schema, which is something we'd try to do only in minor releases.
Having said that, I think we should have another look at the current patch here for 8.1.x (I haven't yet) - and if it's OK for a minor release, commit to 8.1.x. Then we can revisit what to do about 8.0.x for this issue, if anything, afterwards.
Comment #139
ifrikSince I reported the issue, the behaviour has changed. Previously, no term was created at all, if several vocabularies where chosen.
Now, the term is created in the first vocabulary on the list, so it's not lost.
But this first vocabulary is then set as destination for any other of such entity reference field.
If I set up one entity reference fields, using vocabulary 1 and vocabulary 2, the destination is the vocabulary on the top of the list (Vocabulary 1). If I then create another entity reference field, using vocabulary 3 and 4 for another content type, then the destination is still set as vocabulary 1.
Users then can't save the content of this second content type, because the term cannot be created.
The patch in #133 fixes this problem as well.
Comment #140
amateescu commentedRerolled for 8.1.x and fixed the two problems mentioned in #137 1) and 2).
Comment #141
amateescu commentedAnd a new title for what should go into 8.1.x.
Comment #142
claudiu.cristeaI'm setting this back to RTBC per #123.
Comment #144
jibranHere is a reroll.
Comment #145
alexpottDoesn't this mean we need an upgrade path to set the auto create bundle to the first available to replicate the old functionality?
Comment #146
alexpottSetting to needs review for #145
Comment #147
claudiu.cristeaYes, definitely.
Comment #148
amateescu commentedThis should do it.
Comment #149
jibranI have to fix this in DER as well. Let me ping @larowlan for review.
DER is a sub class but it's settings are not stored this way.
$handler_settings can be NULL (in case of DER) so it should have to be a part of if condition.
Comment #150
amateescu commentedDoes this address your concern?
Comment #151
jibranYup thanks.
Comment #152
claudiu.cristeaI think this looks great and can be RTBCed. But I cannot do it because I've contributed to the solution and the code (I only did it when it was a docs diff, in #142). Anybody for a final review? Maybe @jibran or @yched?
Comment #153
jibranYup sure.
Comment #154
lokapujya1-4 not a big deal, but should at least take a look at #5
the changes in these functions can use the new [] instead of array().
Iterate all fields.
an entity reference
Unnecessary long variable name. Should we remove the issue id form the variable name?
Why adding limit_validation_errors? Seems like it could cause the target bundles field to skip validation. Not sure if this is really a problem? But try deselecting all terms and saving.
Comment #155
lokapujyaMore on #5:Once you save the entity reference field without a target bundle selected, then the "Create referenced entities if they don't already exist" checkbox does not hide the "Store new Items" dropdown (even after selecting 2 bundles.)
Comment #156
amateescu commented#154.1, .2 and .3: Fixed.
#154.4: I think it's better to keep the issue id there for clarity and future updates to that file/code.
#154.5: and #155 I can not reproduce the wrong behavior, when I de-select all target bundles and try to submit the form I get the proper validation error ("Content types field is required.").
Comment #157
lokapujya#154.5: I agree that the form gives the proper validation error. The problem is that the form still saves. If you refresh the page, you will see that target bundles remain deselected. I guess I'm expecting it to work like the label and not submit. Couldn't find any other examples of required checkboxes in Core, so maybe that's just the way it works.
#155 seems to be an issue with states.js, perhaps should be a new issue. The checkbox works correctly when javascript is not aggregated.
I actually discovered the problem by:
1. use a content type as the reference type. Initially, no target bundles are selected.
2. select the target bundles: page and article - store new items select shows up, even though we haven't done step 3 yet.
3. click "Create referenced entities if they don't already exist"
4. click "Create referenced entities if they don't already exist" again - store new items doesn't hide
Then, I noticed this only happens when there are initially no target bundles selected. But that should never happen anyway for taxonomy term because it's supposed to be required.
Comment #158
lokapujyaThanks for fixing 1-3. I created a new related issue #2656546 for the problem described in #157.
Comment #159
droplet commentedI followed steps in #2656546: javascript form states don't work and got PHP errors:
The website encountered an unexpected error. Please try again later.
** revert the patch and works.
Comment #160
droplet commentedComment #161
lokapujyaOn which step did you get the error? I know there is a javascript UI issue, but I didn't see that PHP error.
Comment #162
droplet commented1. add `content` reference
2. select Type of item to reference : Content type
3. Save save save
4. edit field
5. click "Create referenced entities if they don't already exist"
6. save save
7. edit again -> HIT error
Comment #163
claudiu.cristea@droplet, did you run the update script?
Comment #164
droplet commentedah right. back to prev state.
I didn't test JS part yet but if that introduced from this patch, I think we should fix them together.
Comment #165
catchIt'd be nice if there was a way to flag this in the form definition. Reminds me a bit of $user->data having to do it manually. Not for here though, but wondering whether we have the same trouble elsewhere.
What if we go from two bundles down to one? Could we not leave auto-create on but remove the bundle setting?
Or we might want to log this similar to below either way?
I'm not convinced about showing the exception on the widget. This could mean that regular site visitors get fatal errors (and I don't yet see a warning being shown on the field UI page with this patch, so only on entity forms which is not where you can fix this). Feels more like we should disable either the autocreate, or the field entirely, + trigger_error()?
This shows the problem with the exception even more.
Saving the field with the wrong configuration doesn't show an exception, viewing the entity form does.
I'd rather see a config listener that throws the exception so you can never get into this situation in the first place, then if we think there are cases where something could go wrong (race condition with the update function not having been run yet?) trigger_error() in the UI.
Comment #166
amateescu commentedI don't think we can rely on a config listener for this situation because that won't run for base field updates.
How about just disabling the auto-create functionality + logging a critical watchdog message in the widget instead of throwing an exception, just like we do in the "last available target bundle was deleted" case? That way, regular site visitors will be able to use the field (partially, at least) and site admins should see the problem pretty soon, given its critical status.
Comment #167
amateescu commentedOk, this should do it.
If the referenced entity type has more than one bundle at any point in time, we should not make any assumptions on which bundle we can use for auto-create because that could have security implications, so it's safer to just disable the feature.
Comment #168
amateescu commentedThe small feedback from @catch has been addressed, so setting back to RTBC.
Comment #171
catchCommitted/pushed to 8.2.x and cherry-picked to 8.1.x. Thanks!
Added review credit post-commit.
Comment #172
catchAdding review credit.
Comment #174
jibranWe need a followup for this.