Problem/Motivation
in #2976334: Allow Custom blocks to be set as non-reusable adding access restriction based on where it was used. we introduced non-reusable blocks.
We don't want them to be selectable as entity reference items(or they would be being reused.)
block_content_query_entity_reference_alter() stops them from being selected. This function is needed because there may have been selection plugins written before this issue. they should not select non-reusable blocks.
but it would be clearer if we also had a default entity reference selection plugin for Custom block entities that did not allow selecting non-reusable blocks.
Proposed resolution
- introduce
\Drupal\block_content\Plugin\EntityReferenceSelection\BlockContentSelection - update
block_content_query_entity_reference_alter()to not alter the query if this class is used - Move testing of this to
\Drupal\Tests\system\Functional\Entity\EntityReferenceSelection\EntityReferenceSelectionAccessTest - 🎉
Remaining tasks
- Write patch
- review
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|
Issue fork drupal-2987159
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 2987159-create-an-entity
changes, plain diff MR !11961
Comments
Comment #2
tedbowI chatted with @amateescu and he said:
So I have crossed of 4-5 from the proposed solution. Will delete when he confirms this is what he meant.
This patch does the other 3 items.
Comment #3
tedbowRemoving steps 4 & 5
Comment #11
smustgrave commentedIs this still relevant with Drupal9.5?
Comment #13
smustgrave commentedClosing as outdated as additional info was requested 6 months ago.
If still an issue please reopen with an updated issue summary
Thanks!
Comment #14
amateescu commentedJust checked Drupal 10.1 and we don't have a CustomBlockSelection plugin, so this is still relevant, as well as the issue summary.
Here's a review for the patch:
We should add a deprecation here to make developers aware of the new selection plugin, so we can remove this hook implementation in Drupal 11.
This new selection plugin also needs to implement the two methods from
SelectionWithAutocreateInterface:createNewEntity()andvalidateReferenceableNewEntities().Copy/paste comment needs to be fixed.
Comment #15
berdir1. Don't you get the per entity type selection plugin by default if you currently have that selected too? It wouldn't apply to a custom plugin, but then you probably know what you're doing and are filtering it out too? What I mean is, do we still need that hook at all, even now?
It's not clear to me why we're moving test coverage into system module, the logic is still in block_content, we could just keep the test, would be much easier to confirm that it doesn't change.
That it tests comment and other handlers is for historical reasons, it used to be in the entity_reference module and tests were moved into core/system.module when that was deprecated. If anything we should have separate issues to split that up and move it to where each handler is.
Comment #18
acbramley commentedRolled this into an MR and:
1. Reverted the test changes, not sure if we need any additional coverage
2. Added a deprecation to the query_alter hook
3. Swapped to attributes
4. Added ::validateReferenceableNewEntities to the new plugin, I don't think we need ::createNewEntity since reusable defaults to TRUE
Comment #20
acbramley commentedComment #21
smustgrave commentedUpdated the version but not 100% how to best test this one.
Comment #22
smustgrave commentedBelieve all threads/feedback has been addressed.
Comment #23
quietone commentedI updated credit and didn't find any unanswered questions.
Comment #24
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #25
acbramley commentedComment #26
catchThis needs a rebase.
The issue title makes it sound like we're adding a second entity reference selection handler, but we're just overriding the default entity one and including the filtering in it. I don't know if that's just me mis-reading the title or if there's a tweak that would make it a bit clearer. After understanding the actual change this all looks good to me.
Comment #27
acbramley commentedRebased and updated the deprecation message.
Comment #28
catchWe can still do this in 11.3 - updated the deprecation message for 11.3.0 instead of 11.4.
Committed/pushed to 11.x, and cherry-picked to 11.3.x, thanks!