You are here

function User::get_argument in Views (for Drupal 7) 8.3

Return the default argument.

This needs to be overridden by every default argument handler to properly do what is needed.

Overrides ArgumentDefaultPluginBase::get_argument

File

lib/Views/user/Plugin/views/argument_default/User.php, line 40
Definition of Views\user\Plugin\views\argument_default\User.

Class

User
Default argument plugin to extract a user via menu_get_object.

Namespace

Views\user\Plugin\views\argument_default

Code

function get_argument() {
  foreach (range(1, 3) as $i) {
    $user = menu_get_object('user', $i);
    if (!empty($user)) {
      return $user->uid;
    }
  }
  foreach (range(1, 3) as $i) {
    $user = menu_get_object('user_uid_optional', $i);
    if (!empty($user)) {
      return $user->uid;
    }
  }
  if (!empty($this->options['user'])) {
    foreach (range(1, 3) as $i) {
      $node = menu_get_object('node', $i);
      if (!empty($node)) {
        return $node->uid;
      }
    }
  }
  if (arg(0) == 'user' && is_numeric(arg(1))) {
    return arg(1);
  }
  if (!empty($this->options['user'])) {
    if (arg(0) == 'node' && is_numeric(arg(1))) {
      $node = node_load(arg(1));
      if ($node) {
        return $node->uid;
      }
    }
  }

  // If the current page is a view that takes uid as an argument, return the uid.
  $view = views_get_page_view();
  if ($view && isset($view->argument['uid'])) {
    return $view->argument['uid']->argument;
  }
}