class TestAccessBlock
Same name in other branches
- 9 core/modules/block/tests/modules/block_test/src/Plugin/Block/TestAccessBlock.php \Drupal\block_test\Plugin\Block\TestAccessBlock
- 10 core/modules/block/tests/modules/block_test/src/Plugin/Block/TestAccessBlock.php \Drupal\block_test\Plugin\Block\TestAccessBlock
- 11.x core/modules/block/tests/modules/block_test/src/Plugin/Block/TestAccessBlock.php \Drupal\block_test\Plugin\Block\TestAccessBlock
Provides a block to test access.
Plugin annotation
@Block(
id = "test_access",
admin_label = @Translation("Test block access")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Component\Plugin\ContextAwarePluginBase extends \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\ContextAwarePluginInterface
- class \Drupal\Core\Plugin\ContextAwarePluginBase extends \Drupal\Component\Plugin\ContextAwarePluginBase implements \Drupal\Core\Plugin\ContextAwarePluginInterface, \Drupal\Core\Cache\CacheableDependencyInterface uses \Drupal\Core\TypedData\TypedDataTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait
- class \Drupal\Core\Block\BlockBase extends \Drupal\Core\Plugin\ContextAwarePluginBase implements \Drupal\Core\Block\BlockPluginInterface, \Drupal\Core\Plugin\PluginWithFormsInterface, \Drupal\Core\Render\PreviewFallbackInterface uses \Drupal\Core\Block\BlockPluginTrait, \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait
- class \Drupal\block_test\Plugin\Block\TestAccessBlock extends \Drupal\Core\Block\BlockBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\Core\Block\BlockBase extends \Drupal\Core\Plugin\ContextAwarePluginBase implements \Drupal\Core\Block\BlockPluginInterface, \Drupal\Core\Plugin\PluginWithFormsInterface, \Drupal\Core\Render\PreviewFallbackInterface uses \Drupal\Core\Block\BlockPluginTrait, \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait
- class \Drupal\Core\Plugin\ContextAwarePluginBase extends \Drupal\Component\Plugin\ContextAwarePluginBase implements \Drupal\Core\Plugin\ContextAwarePluginInterface, \Drupal\Core\Cache\CacheableDependencyInterface uses \Drupal\Core\TypedData\TypedDataTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait
- class \Drupal\Component\Plugin\ContextAwarePluginBase extends \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\ContextAwarePluginInterface
Expanded class hierarchy of TestAccessBlock
File
-
core/
modules/ block/ tests/ modules/ block_test/ src/ Plugin/ Block/ TestAccessBlock.php, line 21
Namespace
Drupal\block_test\Plugin\BlockView source
class TestAccessBlock extends BlockBase implements ContainerFactoryPluginInterface {
/**
* Tests the test access block.
*
*
* @param array $configuration
* The plugin configuration, i.e. an array with configuration values keyed
* by configuration option name. The special key 'context' may be used to
* initialize the defined contexts by setting it to an array of context
* values keyed by context names.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\State\StateInterface $state
* The state.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, StateInterface $state) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->state = $state;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container->get('state'));
}
/**
* {@inheritdoc}
*/
protected function blockAccess(AccountInterface $account) {
return $this->state
->get('test_block_access', FALSE) ? AccessResult::allowed()->setCacheMaxAge(0) : AccessResult::forbidden()->setCacheMaxAge(0);
}
/**
* {@inheritdoc}
*/
public function build() {
return [
'#markup' => 'Hello test world',
];
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
return Cache::PERMANENT;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
TestAccessBlock::blockAccess | protected | function | ||
TestAccessBlock::build | public | function | ||
TestAccessBlock::create | public static | function | Creates an instance of the plugin. | Overrides ContainerFactoryPluginInterface::create |
TestAccessBlock::getCacheMaxAge | public | function | ||
TestAccessBlock::__construct | public | function | Tests the test access block. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.