Problem/Motivation
When creating a entity reference field targeting a taxonomy term, and setting up to limit the vocabulary, the restriction didn't apply, and all the terms of all vocabularies will be selectable in the field.
Steps to reproduce
1. Go to /admin/structure/taxonomy/add
2. Add 2 vocabularies, Animals and Plants. And each one with 1 term.
3. Go to admin/config/people/accounts/fields/add-field
4. Create a Entity reference field (Taxonomy Term), with *only* Vocabulary Animals.
5. Edit your account profile and see that all the terms are selectable, when it should show only Animal terms.
6. It's more obvious when the display of the field is in checkbox view mode
admin/config/people/accounts/form-display
Proposed resolution
Fix the bug in the TermSelection.php class.
Create a test to avoid happening again.
Remaining tasks
Review the patch
User interface changes
Non
API changes
Non
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | interdiff-12-14.txt | 682 bytes | corbacho |
| #14 | 2401195-14.patch | 3.68 KB | corbacho |
Comments
Comment #1
corbacho commentedPatch with test included. This is the first test I write, so please, review carefully
Comment #2
joachim commentedLooks good to me. Confirming the bug and the fix.
Might be an idea to upload just the tests to ascertain that they fail without the fix.
Upping to major in light of #1847596: Remove Taxonomy term reference field in favor of Entity reference.
Comment #3
berdir@joachim: Thanks for finding this.
Fix is mostly the same as mine over in #2247953: Entity reference select widget ignores bundle filter that you closed as duplicate. I like this, makes it a bit more readable than my quickfix.
Test looks good, just a bunch of nitpicks on coding standards and documentation. Tagging novice to fix that, then it should be ready.
Should be Contains \Drupal... (we should really fill a task to get rid of all the old ones, people always copy wrong examples).
TermEntityReferenceTest maybe?
Should have the usual "Modules to enable.\n@var array" docblock.
No need to keep an empty setUp() method.
The first line needs to be a single line (stupid for tests, but that's the rule atm..). Just make a sentence of the test method name... You can keep the existing part as a description below that.
Should use FieldStorageConfig::create()/FieldConfig::create()
Comment is missing a . at the end.
Comment #4
idebr commentedI'll work on the review by Berdir
Comment #5
idebr commentedComment #6
idebr commentedComment #7
berdirI don't think that's necessary, that would only be useful if we would use them in multiple methods.
Everything else looks fine.
Pro-tip: Upload the fail patch first, the testbot only sets the issue status to needs work if the last uploaded patch fails.
Comment #9
idebr commentedComment #11
berdirOne last nitpick, sorry.
I don't think the Term and TermSelection classes are used in the test?
Comment #12
idebr commentedYou are correct :)
Comment #14
corbacho commentedThanks for following up the issue @idebr @joachim and specially @Berdir for the useful nitpicking, I learned quite a lot from those comments :)
About
/Drupalissue.. I searched, and currently In the whole codebase, there are 5175 usagesDrupal/(starting with space) out of 22726 times thatDrupal/is used in comments. I don't know if a patch affecting so many files would be acceptable, do we open an issue ?I made a typo: "ensure that that" in one of the comments, fixed in the patch attached.
Comment #15
idebr commentedI believe Berdir was referring to this change. There are a lot of test files where the TestClass docblock looks like this currently in HEAD.
Comment #16
berdirGreat, I think this is good to go :)
Yes, I just meant the @file declaration. But even of those, there are almost 1000 in core. But every second patch has that wrong because people copy from other files. That's what we get for changing a standard three times ;)
Comment #17
idebr commentedComment #18
alexpottThis issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 7bb4e4d and pushed to 8.0.x. Thanks!