Problem/Motivation
Currently, the module offers autocomplete, which is okay for taxonomy terms, but may not be ideal for other cases.
It would be useful if the module could introduce a setting which widget to use. Later that should be possible per entity type / bundle but for the start I think it would be good enough to have a global setting maybe and allow choosing from the supported widgets. Currently, the widget is a constant.
Comments
Comment #2
zeeshan_khan commentedThis has been implemented in the
1.0.xbranch.What was done
Configuration > Content authoring > Canvas Entity
Reference.
Autocomplete (
entity_reference_autocomplete) orAutocomplete (tags)
(
entity_reference_autocomplete_tags).type: arrayin the component schema)always use the tags autocomplete regardless of this setting — only
single-value props are affected.
canvas_entity_reference.settingsunder thewidgetkey and defaults to
entity_reference_autocomplete.widget: type: stringto the config schema and adefault value to
config/install/canvas_entity_reference.settings.yml.The taxonomy-specific settings (target vocabularies, auto-create) have been
moved into a separate collapsible fieldset on the same form to keep the UI
clean as more entity types are supported.
@anybody - I have added new release with all the changes 1.0.1
Comment #3
zeeshan_khan commentedComment #4
anybody@zeeshan_khan thank you very much for implementing that superfast!
I was thinking about this again and I think instead of the setting it might make sense to solve like you did in #3588651: Get further values (or tid instead of name) from the (Taxonomy Term) entity.
E.g.
x-entity-widgetwhichThat way it can be flexibly defined by instance in the $ref, just like the field and doesn't need global settings!
BTW (if you're interested) I think it might make sense to use Merge Requests and alpha/beta/rc versions maybe for the future, because we're starting to talk about breaking changes in stable releases here... Are you aware of that?
It's your module and your decision, so I hope it's fine to learn if you didn't know.
Comment #5
anybodyComment #6
anybodyPPS: With that feedback addressed, you might also add an example using the new properties and add a screenshot using for example a select instead of the autocomplete on the module page?
Comment #7
anybodyPS: Also something for 1.1.x and removal in 2.x then IMHO.
Sorry that this didn't come to my mind earlier.
Comment #8
zeeshan_khan commented(Note: All changes live in dev release).
Added x-entity-widget annotation support. Component authors can now overridethe widget per-prop directly in the component YAML:
# Single-value prop — override the global widget setting
term_ref:
type: ['string', 'null']
x-entity-type: taxonomy_term
x-entity-widget: entity_reference_autocomplete
# Array prop — explicitly declare the widget
terms:
type: array
x-entity-widget: entity_reference_autocomplete_tags
items:
type: ['string', 'null']
x-entity-type: taxonomy_term
When omitted, the prop falls back to the global widget setting (single-value) or tags autocomplete (array). One important constraint: the tags widget (entity_reference_autocomplete_tags) requires an array-type prop — using it on a single string prop will only retain one value since the transform produces an array.
Support for contrib widgets like Tagify or Entity Browser is possible as long as the contrib module registers Canvas transform metadata for its widget plugin. That is outside the scope of this module.
Regarding version management — noted. Going forward, breaking changes will go through alpha/beta/rc before a stable tag.
Comment #9
zeeshan_khan commentedComment #10
anybodyGreat work @zeeshan_khan! For all cases where something "fails", e.g. due to incompatibility or wrong parameters I'd suggest at least logging a warning or error (what ever applies) to let the administrator know.
Didn't check the code yet, maybe you already did where possible.
Before releasing this: Do you think
x-entity-widgetis the perfect name or should we think about it again? I just wanted to give an example.Could also be something like
x-entity-form-widgetor whatever, I'm not sure myself. But once released we won't be able to change this anymore.Comment #11
anybodyPS: For contrib module integration I think giving a clear example in the README would make sense?
Comment #12
zeeshan_khan commentedPS: For contrib module integration I think giving a clear example in the README would make sense? - correct
But this module already includes 7 demo components adding extra lines in Readme doesn't make sense to me but I am open for suggestions.
Comment #13
anybodyYes I agree, just though they need additional (PHP) code to make it work. Didn't dig deeper into how they have to integrate, sorry if I got something wrong.
Comment #14
anybodyFor #10 discussion about the final name - before we RTBC this finally.
Comment #15
zeeshan_khan commentedThank you for helping in making the module better thanks a ton!
Thanks for the feedback.
On the naming — x-entity-widget is intentional and consistent with the existing annotation pattern (x-entity-type, x-entity-field, x-entity-type-bundles). In Drupal, "widget" already unambiguously refers to a form input widget, so adding "form" would be redundant. I'd like to keep x-entity-widget unless there is a specific reason the shorter name would cause confusion.
On logging — the module already logs a warning for unrecognised $ref URIs. Widget validation is harder to do at shape-matching time because the field widget plugin system is only fully initialised during form build. If an incompatible or missing widget ID is passed, Drupal's own field widget manager will throw or fall back and log at that point. I can add a note to the README making this explicit so site builders know what to look for.
On the README contrib integration example — good suggestion. I will add a short section covering what a contrib module needs to do (register Canvas transform metadata via hook_field_widget_info_alter) with Tagify as an illustrative example.
Does that sound right, or do you want to reconsider the name before I update the README and commit?
Comment #17
anybodyThank you Zeeshan! I'm totally fine with your decisions made and it's your module :)
You're welcome!
Comment #18
zeeshan_khan commentedHaha! (my module) its not like that, its our module you have as much rights as I do on the decisions
PR - https://git.drupalcode.org/project/canvas_entity_reference/-/merge_reque...
Comment #23
zeeshan_khan commented