Problem/Motivation
@amateescu reported a bug with the media library field widget in #2988617: Creating media with the media library upload is broken for unlimited cardinality:
I think it's worth noting that the target_bundles setting of the ER field has three states:
- NULL: all bundles are referenceable
- []: no bundle is referenceable
- ['some_bundle']: only some_bundle is referenceableThis is documented in \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::defaultConfiguration, and maybe some logic of this patch needs to be updated based on this information.
In practice, target_bundles can only be NULL if a user has not configured their field, since it's a required field (see \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::buildConfigurationForm). Either way, the widget and upload form don't handle this case but probably should.
This bug has been unintentionally fixed by the hullaballoo of #3020716: Add vertical tabs style menu to media library, but we should really have a test in core to prevent it from regressing in the future.
Proposed resolution
Add a test of the NULL case for target_bundles and allow all types.
Remaining tasks
Commit the patch.
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 2989503-11.patch | 6.16 KB | seanb |
| #11 | interdiff-6-11.txt | 3.08 KB | seanb |
| #6 | 2989503-6.patch | 5.75 KB | seanb |
Comments
Comment #2
seanbThis has been fixed in #3020716: Add vertical tabs style menu to media library. We can close this issue when that lands.
Comment #3
balsamaComment #4
phenaproximaComment #5
amateescu commentedI think the NW status is when there's a patch in the issue, we don't have one here so it should be active :)
Comment #6
seanbAdded a field without target bundles with a test to show #3020716: Add vertical tabs style menu to media library fixed it.
Comment #7
phenaproximaMaybe I'm missing something, but it looks like target_bundles is an array...but it should be explicitly null in order for this test to be effective.
Comment #8
wim leers✅ Configurable field for testing this with empty
target_bundles.✅ Empty
target_bundles.✅ Verifies this field exists.
✅ This then tests that all bundles are visible.
Comment #9
phenaproximaNot quite. The issue title says that we need to prove it works if target_bundles is NULL, not an empty array. Ideally that is what the test we're adding here would address.
Comment #10
phenaproximaNit: I think these assertions can all become
$this->assertTrue($menu->hasLink('Foo')).Comment #11
seanbFixed #9 / #10
Comment #12
phenaproximaRTBC once green. Thanks!
Comment #13
phenaproximaComment #14
alexpottCommitted 0b6e897 and pushed to 8.7.x. Thanks!