mercury_editor-2.0.x-dev/modules/mercury_editor_templates/src/MeTemplateAccessControlHandler.php

modules/mercury_editor_templates/src/MeTemplateAccessControlHandler.php
<?php

namespace Drupal\mercury_editor_templates;

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 ME template entity type.
 */
class MeTemplateAccessControlHandler extends EntityAccessControlHandler {

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

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

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

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

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

  }

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

}

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

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