podcast_publisher-1.0.0-alpha3/src/PodcastAccessControlHandler.php

src/PodcastAccessControlHandler.php
<?php

namespace Drupal\podcast_publisher;

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 podcast entity type.
 */
class PodcastAccessControlHandler extends EntityAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {

    switch ($operation) {
      case 'view':
        return AccessResult::allowedIfHasPermission($account, 'view podcast');

      case 'update':
        return AccessResult::allowedIfHasPermissions($account, [
          'edit podcast',
          'administer podcast',
        ], 'OR');

      case 'delete':
        return AccessResult::allowedIfHasPermissions($account, [
          'delete podcast',
          'administer podcast',
        ], 'OR');

      default:
        // No opinion.
        return AccessResult::neutral();
    }

  }

  /**
   * {@inheritdoc}
   */
  protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
    return AccessResult::allowedIfHasPermissions($account, [
      'create podcast',
      'administer podcast',
    ], 'OR');
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc