You are here

CurrentUserName.php in Maestro 8.2

Same filename and directory in other branches
  1. 3.x src/Plugin/views/argument_default/CurrentUserName.php

File

src/Plugin/views/argument_default/CurrentUserName.php
View source
<?php

namespace Drupal\maestro\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 name.
 *
 * No Options for this plugin.
 *
 * @ViewsArgumentDefault(
 *   id = "current_user_name",
 *   title = @Translation("Username from logged in user")
 * )
 */
class CurrentUserName extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {

  /**
   * {@inheritdoc}
   */
  public function getArgument() {
    return \Drupal::currentUser()
      ->getAccountName();
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheMaxAge() {
    return Cache::PERMANENT;
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheContexts() {
    return [
      'user',
    ];
  }

}

Classes

Namesort descending Description
CurrentUserName Default argument plugin to extract the current user name.