Version 1
[yaffs-website] / web / core / modules / user / src / Plugin / views / argument_default / CurrentUser.php
diff --git a/web/core/modules/user/src/Plugin/views/argument_default/CurrentUser.php b/web/core/modules/user/src/Plugin/views/argument_default/CurrentUser.php
new file mode 100644 (file)
index 0000000..b8aeeea
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+namespace Drupal\user\Plugin\views\argument_default;
+
+use Drupal\Core\Cache\Cache;
+use Drupal\Core\Cache\CacheableDependencyInterface;
+use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
+
+/**
+ * Default argument plugin to extract the current user
+ *
+ * This plugin actually has no options so it does not need to do a great deal.
+ *
+ * @ViewsArgumentDefault(
+ *   id = "current_user",
+ *   title = @Translation("User ID from logged in user")
+ * )
+ */
+class CurrentUser extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getArgument() {
+    return \Drupal::currentUser()->id();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCacheMaxAge() {
+    return Cache::PERMANENT;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCacheContexts() {
+    return ['user'];
+  }
+
+}