Version 1
[yaffs-website] / web / core / modules / views / tests / modules / views_test_data / src / Plugin / views / area / TestExample.php
diff --git a/web/core/modules/views/tests/modules/views_test_data/src/Plugin/views/area/TestExample.php b/web/core/modules/views/tests/modules/views_test_data/src/Plugin/views/area/TestExample.php
new file mode 100644 (file)
index 0000000..74818e8
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+
+namespace Drupal\views_test_data\Plugin\views\area;
+
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Session\AccountInterface;
+use Drupal\views\Plugin\views\area\AreaPluginBase;
+
+/**
+ * Test area plugin.
+ *
+ * @see \Drupal\views\Tests\Handler\AreaTest
+ *
+ * @ViewsArea("test_example")
+ */
+class TestExample extends AreaPluginBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function access(AccountInterface $account) {
+    return $this->options['custom_access'];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function defineOptions() {
+    $options = parent::defineOptions();
+    $options['string'] = ['default' => ''];
+    $options['custom_access'] = ['default' => TRUE];
+
+    return $options;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
+    parent::buildOptionsForm($form, $form_state);
+    $this->globalTokenForm($form, $form_state);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function render($empty = FALSE) {
+    if (!$empty || !empty($this->options['empty'])) {
+      return [
+        '#markup' => $this->globalTokenReplace($this->options['string']),
+      ];
+    }
+    return [];
+  }
+
+}