function Date::getDefaultArgument

Same name in other branches
  1. 8.9.x core/modules/views/src/Plugin/views/argument/Date.php \Drupal\views\Plugin\views\argument\Date::getDefaultArgument()
  2. 10 core/modules/views/src/Plugin/views/argument/Date.php \Drupal\views\Plugin\views\argument\Date::getDefaultArgument()
  3. 11.x core/modules/views/src/Plugin/views/argument/Date.php \Drupal\views\Plugin\views\argument\Date::getDefaultArgument()

Gets the date default argument, formatted appropriately for this argument.

Overrides ArgumentPluginBase::getDefaultArgument

File

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

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);
}

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