Version 1
[yaffs-website] / web / core / modules / views / tests / modules / views_test_data / src / Plugin / views / access / StaticTest.php
diff --git a/web/core/modules/views/tests/modules/views_test_data/src/Plugin/views/access/StaticTest.php b/web/core/modules/views/tests/modules/views_test_data/src/Plugin/views/access/StaticTest.php
new file mode 100644 (file)
index 0000000..5515986
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+
+namespace Drupal\views_test_data\Plugin\views\access;
+
+use Drupal\Core\Session\AccountInterface;
+use Drupal\views\Plugin\views\access\AccessPluginBase;
+use Symfony\Component\Routing\Route;
+
+/**
+ * Tests a static access plugin.
+ *
+ * @ViewsAccess(
+ *   id = "test_static",
+ *   title = @Translation("Static test access plugin"),
+ *   help = @Translation("Provides a static test 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'],
+    ];
+  }
+
+}