MediaTypeAccessControlHandler.php 810 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace Drupal\media;
  3. use Drupal\Core\Access\AccessResult;
  4. use Drupal\Core\Entity\EntityAccessControlHandler;
  5. use Drupal\Core\Entity\EntityInterface;
  6. use Drupal\Core\Session\AccountInterface;
  7. /**
  8. * Defines the access control handler for the "Media Type" entity type.
  9. *
  10. * @see \Drupal\media\Entity\MediaType
  11. */
  12. class MediaTypeAccessControlHandler extends EntityAccessControlHandler {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. protected $viewLabelOperation = TRUE;
  17. /**
  18. * {@inheritdoc}
  19. */
  20. protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
  21. if ($operation === 'view label') {
  22. return AccessResult::allowedIfHasPermission($account, 'view media');
  23. }
  24. else {
  25. return parent::checkAccess($entity, $operation, $account);
  26. }
  27. }
  28. }