Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
There is currently no access control handler for the Media Bundle entities. As a result, users who do not have the administer media bundles
permission cannot view or see the Provider (bundle label) on the /admin/content/media
display.
Possible code solution
I've been able to solve this for the particular project that this issue has arisen in through a custom access handler implementation and specifying it via hook_entity_type_build()
. However, I'd hazard a guess that this is probably a common issue that needs a permanent solution.
<?php
namespace Drupal\media_entity;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Defines the access control handler for the Media Bundle entity.
*/
class MediaBundleAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
switch ($operation) {
case 'view':
return AccessResult::allowedIfHasPermission($account, 'access media overview');
}
return parent::checkAccess($entity, $operation, $account);
}
}
Comment | File | Size | Author |
---|---|---|---|
#3 | 2884175-3.patch | 1.5 KB | Rolf van de Krol |
|
Comments
Comment #2
BerdirAgreed in general, I would recommend to do this through the new view label operation because creating full view access can be somewhat problematic, e.g. when combined with REST.
Also, this will need to be synced with core as media is now in Drupal core.
Comment #3
Rolf van de Krol CreditAttribution: Rolf van de Krol commentedThis patch adds an access control handler for media bundle. Without it, the field for the media bundle in views does not work correctly. Changing the operation to 'view label' does not work, so it might need some reworking.
Comment #4
Rolf van de Krol CreditAttribution: Rolf van de Krol commentedComment #5
drup16 CreditAttribution: drup16 commentedI was able to test this and it is showing in views now.