function User::getArgument

Same name in other branches
  1. 8.9.x core/modules/user/src/Plugin/views/argument_default/User.php \Drupal\user\Plugin\views\argument_default\User::getArgument()
  2. 10 core/modules/user/src/Plugin/views/argument_default/User.php \Drupal\user\Plugin\views\argument_default\User::getArgument()
  3. 11.x core/modules/user/src/Plugin/views/argument_default/User.php \Drupal\user\Plugin\views\argument_default\User::getArgument()

Overrides ArgumentDefaultPluginBase::getArgument

File

core/modules/user/src/Plugin/views/argument_default/User.php, line 85

Class

User
Default argument plugin to extract a user from request.

Namespace

Drupal\user\Plugin\views\argument_default

Code

public function getArgument() {
    // If there is a user object in the current route.
    if ($user = $this->routeMatch
        ->getParameter('user')) {
        if ($user instanceof UserInterface) {
            return $user->id();
        }
    }
    // If option to use node author; and node in current route.
    if (!empty($this->options['user']) && ($node = $this->routeMatch
        ->getParameter('node'))) {
        if ($node instanceof NodeInterface) {
            return $node->getOwnerId();
        }
    }
}

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