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.
Proposed resolution
Handle the NULL case for target_bundles and allow all types.
Remaining tasks
Write a patch.
User interface changes
None.
API changes
None.
Data model changes
None.