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.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

anybody created an issue. See original summary.

zeeshan_khan’s picture

This has been implemented in the 1.0.x branch.

What was done

  • Added a Widget settings section to the admin form at
    Configuration > Content authoring > Canvas Entity
    Reference
    .
  • Site builders can now choose the default single-value widget:
    Autocomplete (entity_reference_autocomplete) or
    Autocomplete (tags)
    (entity_reference_autocomplete_tags).
  • Multi-value props (type: array in the component schema)
    always use the tags autocomplete regardless of this setting — only
    single-value props are affected.
  • The selected widget is stored in
    canvas_entity_reference.settings under the widget
    key and defaults to entity_reference_autocomplete.
  • Added widget: type: string to the config schema and a
    default 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

zeeshan_khan’s picture

Status: Active » Needs review
anybody’s picture

@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-widget which

  • if omitted falls back to the autocomplete
  • if given is validated against available entity reference widgets and
    • uses the defined entity_reference widget if valid
    • shows an error if invalid

That 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.

anybody’s picture

Version: 1.0.0 » 1.0.1
Status: Needs review » Needs work
anybody’s picture

PPS: 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?

anybody’s picture

PS: Also something for 1.1.x and removal in 2.x then IMHO.

Sorry that this didn't come to my mind earlier.

zeeshan_khan’s picture

(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.

zeeshan_khan’s picture

Status: Needs work » Needs review
anybody’s picture

Priority: Minor » Normal

Great 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-widget is 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-widget or whatever, I'm not sure myself. But once released we won't be able to change this anymore.

anybody’s picture

PS: For contrib module integration I think giving a clear example in the README would make sense?

zeeshan_khan’s picture

PS: 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.

anybody’s picture

Yes 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.

anybody’s picture

Status: Needs review » Needs work

For #10 discussion about the final name - before we RTBC this finally.

zeeshan_khan’s picture

Thank 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?

  • zeeshan_khan committed 32970258 on issue/3588752-readme-contrib-widget-example
    Issue #3588752 by zeeshan_khan: Add contrib widget integration example...
anybody’s picture

Status: Needs work » Reviewed & tested by the community

Thank you Zeeshan! I'm totally fine with your decisions made and it's your module :)

You're welcome!

zeeshan_khan’s picture

Haha! (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...

  • zeeshan_khan committed b660a355 on issue/3588752-readme-contrib-widget-example
    Issue #3588752 by zeeshan_khan: Fix cspell — add flagWords block and...

  • zeeshan_khan committed 2e2a354c on issue/3588752-readme-contrib-widget-example
    Issue #3588752 by zeeshan_khan: Fix cspell — add flagWords block and...

  • zeeshan_khan committed a6fbe31b on issue/3588752-readme-contrib-widget-example
    Issue #3588752 by zeeshan_khan: Add contrib widget integration example...

  • zeeshan_khan committed 42cf2614 on 1.0.x
    Issue #3588752 by zeeshan_khan: Add contrib widget integration example...
zeeshan_khan’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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