Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293655

Make MediaLibraryWidget more flexible

$
0
0

Problem/Motivation

If someone extends `EntityReferenceItem` and creates their own version of the `entity_reference_something` field type, it's not easy to make it work with (extended) `MediaLibraryWidget`, because `checkAccess` method in `MediaLibraryFieldWidgetOpener.php` contains check against `entity_reference` field type:

if ($field_definition->getType() !== 'entity_reference') {
  throw new \LogicException('Expected the media library to be opened by an entity reference field.');
}

Steps to reproduce

This is our example: https://git.drupalcode.org/project/entity_reference_media/-/blob/1.0.x/s...
And we had to copy the whole `checkAccess` method, just in order to insert our `entity_reference_media` there:

if ($field_definition->getType() !== 'entity_reference'&& $field_definition->getType() !== 'entity_reference_media') {
  throw new \LogicException('Expected the media library to be opened by an entity reference field.');
}

And it's not a good idea, but we had no choice I think.

Proposed resolution

Maybe to add a new property inside MediaLibraryFieldWidgetOpener.php which defines allowed field types, so people can extend it simply and adapt to their needs. And `checkAccess` method can do check against this property.


Viewing all articles
Browse latest Browse all 293655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>