Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x

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.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal