You are here

FormAssemblyEntityAccessControlHandler.php in FormAssembly 8

File

src/FormAssemblyEntityAccessControlHandler.php
View source
<?php

namespace Drupal\formassembly;

use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;

/**
 * Access controller for the FormAssembly Form entity.
 *
 * @author Shawn P. Duncan <code@sd.shawnduncan.org>
 *
 * Copyright 2018 by Shawn P. Duncan.  This code is
 * released under the GNU General Public License.
 * Which means that it is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 * http://www.gnu.org/licenses/gpl.html
 * @package Drupal\formassembly
 * @see \Drupal\formassembly\Entity\FormAssemblyEntity.
 */
class FormAssemblyEntityAccessControlHandler extends EntityAccessControlHandler {

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

    /** @var \Drupal\formassembly\Entity\FormAssemblyEntityInterface $entity */
    switch ($operation) {
      case 'view':
        return AccessResult::allowedIfHasPermission($account, 'view formassembly form entities');
      case 'update':
        return AccessResult::allowedIfHasPermission($account, 'edit formassembly form entities');
      case 'delete':
        return AccessResult::allowedIfHasPermission($account, 'delete formassembly form entities');
    }

    // Unknown operation, no opinion.
    return AccessResult::neutral();
  }

  /**
   * {@inheritdoc}
   */
  protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
    return AccessResult::allowedIfHasPermission($account, 'add formassembly form entities');
  }

}

Classes

Namesort descending Description
FormAssemblyEntityAccessControlHandler Access controller for the FormAssembly Form entity.