DefinedTestAccessCheck.php

Same filename in other branches
  1. 8.9.x core/modules/system/tests/modules/router_test_directory/src/Access/DefinedTestAccessCheck.php
  2. 10 core/modules/system/tests/modules/router_test_directory/src/Access/DefinedTestAccessCheck.php
  3. 11.x core/modules/system/tests/modules/router_test_directory/src/Access/DefinedTestAccessCheck.php

Namespace

Drupal\router_test\Access

File

core/modules/system/tests/modules/router_test_directory/src/Access/DefinedTestAccessCheck.php

View source
<?php

namespace Drupal\router_test\Access;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\Access\AccessInterface;
use Symfony\Component\Routing\Route;

/**
 * Defines an access checker similar to DefaultAccessCheck.
 */
class DefinedTestAccessCheck implements AccessInterface {
    
    /**
     * Checks access.
     *
     * @param \Symfony\Component\Routing\Route $route
     *   The route to check against.
     *
     * @return \Drupal\Core\Access\AccessResultInterface
     *   The access result.
     */
    public function access(Route $route) {
        if ($route->getRequirement('_test_access') === 'TRUE') {
            return AccessResult::allowed();
        }
        elseif ($route->getRequirement('_test_access') === 'FALSE') {
            return AccessResult::forbidden();
        }
        else {
            return AccessResult::neutral();
        }
    }

}

Classes

Title Deprecated Summary
DefinedTestAccessCheck Defines an access checker similar to DefaultAccessCheck.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.