You are here

public function Date::getDefaultArgument in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/argument/Date.php \Drupal\views\Plugin\views\argument\Date::getDefaultArgument()

Set the empty argument value to the current date, formatted appropriately for this argument.

Overrides ArgumentPluginBase::getDefaultArgument

File

core/modules/views/src/Plugin/views/argument/Date.php, line 108

Class

Date
Argument handler for dates.

Namespace

Drupal\views\Plugin\views\argument

Code

public function getDefaultArgument($raw = FALSE) {
  if (!$raw && $this->options['default_argument_type'] == 'date') {
    return date($this->argFormat, REQUEST_TIME);
  }
  elseif (!$raw && in_array($this->options['default_argument_type'], [
    'node_created',
    'node_changed',
  ])) {
    $node = $this->routeMatch
      ->getParameter('node');
    if (!$node instanceof NodeInterface) {
      return parent::getDefaultArgument();
    }
    elseif ($this->options['default_argument_type'] == 'node_created') {
      return date($this->argFormat, $node
        ->getCreatedTime());
    }
    elseif ($this->options['default_argument_type'] == 'node_changed') {
      return date($this->argFormat, $node
        ->getChangedTime());
    }
  }
  return parent::getDefaultArgument($raw);
}