StaticTest.php

Same filename in other branches
  1. 9 core/modules/views/tests/modules/views_test_data/src/Plugin/views/access/StaticTest.php
  2. 8.9.x core/modules/views/tests/modules/views_test_data/src/Plugin/views/access/StaticTest.php
  3. 10 core/modules/views/tests/modules/views_test_data/src/Plugin/views/access/StaticTest.php

Namespace

Drupal\views_test_data\Plugin\views\access

File

core/modules/views/tests/modules/views_test_data/src/Plugin/views/access/StaticTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\views_test_data\Plugin\views\access;

use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsAccess;
use Drupal\views\Plugin\views\access\AccessPluginBase;
use Symfony\Component\Routing\Route;

/**
 * Tests a static access plugin.
 */
class StaticTest extends AccessPluginBase {
    protected function defineOptions() {
        $options = parent::defineOptions();
        $options['access'] = [
            'default' => FALSE,
        ];
        return $options;
    }
    
    /**
     * {@inheritdoc}
     */
    public function access(AccountInterface $account) {
        return !empty($this->options['access']);
    }
    
    /**
     * {@inheritdoc}
     */
    public function alterRouteDefinition(Route $route) {
        if (!empty($this->options['access'])) {
            $route->setRequirement('_access', 'TRUE');
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function calculateDependencies() {
        return [
            'content' => [
                'StaticTest',
            ],
        ];
    }

}

Classes

Title Deprecated Summary
StaticTest Tests a static access plugin.

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