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);
  }

}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

amcgowanca created an issue. See original summary.

Berdir’s picture

Agreed 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.

Rolf van de Krol’s picture

This 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.

Rolf van de Krol’s picture

Status: Active » Needs review
drup16’s picture

Status: Needs review » Reviewed & tested by the community

I was able to test this and it is showing in views now.