MediaTypeAccessControlHandler.php

Same filename in other branches
  1. 9 core/modules/media/src/MediaTypeAccessControlHandler.php
  2. 8.9.x core/modules/media/src/MediaTypeAccessControlHandler.php
  3. 11.x core/modules/media/src/MediaTypeAccessControlHandler.php

Namespace

Drupal\media

File

core/modules/media/src/MediaTypeAccessControlHandler.php

View source
<?php

namespace Drupal\media;

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 Type" entity type.
 *
 * @see \Drupal\media\Entity\MediaType
 */
class MediaTypeAccessControlHandler extends EntityAccessControlHandler {
    
    /**
     * {@inheritdoc}
     */
    protected $viewLabelOperation = TRUE;
    
    /**
     * {@inheritdoc}
     */
    protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
        if ($operation === 'view label') {
            return AccessResult::allowedIfHasPermission($account, 'view media');
        }
        else {
            return parent::checkAccess($entity, $operation, $account);
        }
    }

}

Classes

Title Deprecated Summary
MediaTypeAccessControlHandler Defines the access control handler for the "Media Type" entity type.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.