RobotAccessController.php

Same filename in other branches
  1. 3.x modules/config_entity_example/src/RobotAccessController.php
  2. 8.x-1.x config_entity_example/src/RobotAccessController.php

Namespace

Drupal\config_entity_example

File

modules/config_entity_example/src/RobotAccessController.php

View source
<?php

namespace Drupal\config_entity_example;

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

/**
 * Defines an access controller for the robot entity.
 *
 * We set this class to be the access controller in Robot's entity annotation.
 *
 * @see \Drupal\config_entity_example\Entity\Robot
 *
 * @ingroup config_entity_example
 */
class RobotAccessController extends EntityAccessControlHandler {
    
    /**
     * {@inheritdoc}
     */
    public function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
        // The $operation parameter tells you what sort of operation access is
        // being checked for.
        if ($operation == 'view') {
            return AccessResult::allowed();
        }
        // Other than the view operation, we're going to be insanely lax about
        // access. Don't try this at home!
        return parent::checkAccess($entity, $operation, $account);
    }

}

Classes

Title Deprecated Summary
RobotAccessController Defines an access controller for the robot entity.