CurrentUser.php

Same filename in other branches
  1. 9 core/modules/user/src/Plugin/views/argument_default/CurrentUser.php
  2. 8.9.x core/modules/user/src/Plugin/views/argument_default/CurrentUser.php
  3. 11.x core/modules/user/src/Plugin/views/argument_default/CurrentUser.php

Namespace

Drupal\user\Plugin\views\argument_default

File

core/modules/user/src/Plugin/views/argument_default/CurrentUser.php

View source
<?php

namespace Drupal\user\Plugin\views\argument_default;

use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsArgumentDefault;
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.
 */
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',
        ];
    }

}

Classes

Title Deprecated Summary
CurrentUser Default argument plugin to extract the current user.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.