backdrop-contrib / github_stats

Track Github statistics of Backdrop CMS projects and display in a Views listing.
https://backdropcms.org/project/github_stats
GNU General Public License v3.0
2 stars 1 forks source link

Incorrect/misleading validation message when using in Entity Reference field #10

Closed yorkshire-pudding closed 1 month ago

yorkshire-pudding commented 1 month ago

Steps to reproduce

  1. Add some records to Github Statistics
  2. On a content type, add an Entity Reference field and point it to Github Statistics
  3. Set the field to Autocomplete or Autocomplete (Tags) and use "Starts with" or "Contains" using the 'name' property of the base table.
  4. Create a node of content type (fill in other mandatory fields) and start typing a name in the ER field
  5. Select from the list
  6. Save

Expected result Node saves with no issues

Actual result Validation error like: Many entities are called Filter Perms. Specify the one you want by appending the id in parentheses, like "Filter Perms (1)" image

Never seen this on other ER fields

indigoxela commented 1 month ago

@yorkshire-pudding I don't think, this is anything that can be addressed in this module.

The message stems from core/modules/entityreference/plugins/selection/EntityReferenceSelectionHandlerGeneric.inc

Can you check your settings for this entity reference field? Is the field setting Hide IDs checked? If so, can you uncheck it and try again?

EDIT: ah, wait, that setting's actually unrelated. The whole handling of this entity seems a bit quirky with entityreference. It's unclear to me, when the ids are attached and when not. But when ids are attached, the field works. And it always works when it's a select list (field widget). Hm... a core bug?

indigoxela commented 1 month ago

Some quick findings (maybe related, maybe not...). The label_key property is hardcoded for core entities in EntityReferenceSelectionHandlerGeneric.inc, that's why search matching with autocomplete doesn't work at all.

But... we might be able to provide something with a class extending EntityReferenceSelectionHandlerGeneric.

See https://github.com/backdrop/backdrop/blob/1.x/core/modules/entityreference/plugins/selection/EntityReferenceSelectionHandlerGeneric.inc#L39

Again: only autocomplete misbehaves, select list works just fine.

indigoxela commented 1 month ago

Yes, it seems to be as simple as that: set the label_key to "name". :wink:

Another thing that came to my mind: do I have to add a permission check in my handler extension? Or is that done automatically? entity_access is called in EntityReferenceSelectionHandlerGeneric, so that check seems correct.

Anyway, @yorkshire-pudding does this fix the problem for you, or is this just an unrelated fix and the problem (missing ID with autocomplete) persists for you?

yorkshire-pudding commented 1 month ago

@indigoxela - Yes I had also found that select lists worked fine and that was going to be my workaround. However, your PR completely fixes it. Thank you 😄