- 🇬🇧United Kingdom malcomio
I think that this is happening because the LibraryItem class does not specify any value for default_reference_revision_settings, which means that the DefaultSelection class is used when querying.
Compare with the Paragraph class, which specifies that the ParagraphSelection EntityReferenceSelection plugin class should be used.
So I think the next step will be:
1. define an EntityReferenceSelection plugin for paragraphs library items
2. update the LibraryItem class to use it
3. implement the buildEntityQuery method to limit the selection based on the parent, similar to ParagraphsLibraryItemHasAllowedParagraphsTypeConstraintValidator - Merge request !68Draft: Issue #3120718: Add from library should only display allowed paragraph types → (Open) created by malcomio
- 🇬🇧United Kingdom mjmorley
I've been working on this to try and get a nice solution, it feels like much better UX.
I think the best solution here would be to set the target bundles in the form alter from a paragraph. In the $context variable we can get the target bundles of the parent field, and then set them on the #selection_settings of field_reusable_paragraph.
This does mean in LibraryItemSelection::buildEntityQuery we can't call parent::buildEntityQuery as it will throw errors. For now in the patch I have just copied relevant code from the parent function, but I guess an alternative would be to store the target bundles in a different field and then use them from there. But it seems clunkier to me.
I have added one patch that has the form_alter built into the paragraphs_library module. I will also add another comment below with a patch that omits the form alter, so people can add their own form alter implementation if they wish.
- Status changed to Needs review
about 1 year ago 2:20pm 13 December 2023 - last update
about 1 year ago Composer require-dev failure - last update
about 1 year ago Patch Failed to Apply - last update
about 1 year ago Patch Failed to Apply - 🇬🇧United Kingdom mjmorley
The last patches were erroneous so here are the patches again but with the fixes in the entity annotation
- last update
about 1 year ago Composer require-dev failure - last update
about 1 year ago Composer require-dev failure - 🇬🇧United Kingdom mjmorley
Having a nightmare here. The last patches didn't have the new custom entity reference selection on.
These two patches should. - last update
about 1 year ago 180 pass - last update
about 1 year ago 180 pass - 🇬🇧United Kingdom malcomio
@mjmorley I'm confused about the difference between the two patches.
What's the difference, and which one is your preferred option?
Also, it's probably easier to create merge request(s) - First commit to issue fork.
- 🇧🇪Belgium dieterholvoet Brussels
I rebased the branch against 8.x-1.x and finished the draft implementation in the MR based on the form alter hook by @mjmorley. I also rewrote
LibraryItemSelection
, now we can keep theparent::buildEntityQuery($match, $match_operator)
call and we don't need to query all paragraph ids of a certain type, which could break for sites with a lot of paragraphs. Now this is actually ready for review, without the need for custom form alters. - 🇧🇪Belgium dieterholvoet Brussels
The MR should be marked as ready, but it seems like I don't have permission to do so.
Has there been any updates on this? I would love to have this functionality, but the patches here don't work for me. I even made a patch myself based on the MR and that also didn't work.