01a99a07918541e010bde9fb9e6b04185bed5f29
[yaffs-website] / web / core / modules / settings_tray / src / Access / BlockPluginHasSettingsTrayFormAccessCheck.php
1 <?php
2
3 namespace Drupal\settings_tray\Access;
4
5 use Drupal\block\BlockInterface;
6 use Drupal\Core\Access\AccessResult;
7 use Drupal\Core\Block\BlockPluginInterface;
8 use Drupal\Core\Plugin\PluginWithFormsInterface;
9 use Drupal\Core\Routing\Access\AccessInterface;
10
11 /**
12  * Determines whether the requested block has a 'settings_tray' form.
13  *
14  * @internal
15  */
16 class BlockPluginHasSettingsTrayFormAccessCheck implements AccessInterface {
17
18   /**
19    * Checks access for accessing a block's 'settings_tray' form.
20    *
21    * @param \Drupal\block\BlockInterface $block
22    *   The block whose 'settings_tray' form is being accessed.
23    *
24    * @return \Drupal\Core\Access\AccessResultInterface
25    *   The access result.
26    */
27   public function access(BlockInterface $block) {
28     /** @var \Drupal\Core\Block\BlockPluginInterface $block_plugin */
29     $block_plugin = $block->getPlugin();
30     return $this->accessBlockPlugin($block_plugin);
31   }
32
33   /**
34    * Checks access for accessing a block plugin's 'settings_tray' form.
35    *
36    * @param \Drupal\Core\Block\BlockPluginInterface $block_plugin
37    *   The block plugin whose 'settings_tray' form is being accessed.
38    *
39    * @return \Drupal\Core\Access\AccessResultInterface
40    *   The access result.
41    *
42    * @see settings_tray_preprocess_block()
43    */
44   public function accessBlockPlugin(BlockPluginInterface $block_plugin) {
45     return AccessResult::allowedIf($block_plugin instanceof PluginWithFormsInterface && $block_plugin->hasFormClass('settings_tray'));
46   }
47
48 }