Date.php

Same filename in this branch
  1. 10 core/modules/views/src/Plugin/views/sort/Date.php
  2. 10 core/modules/views/src/Plugin/views/field/Date.php
  3. 10 core/modules/views/src/Plugin/views/filter/Date.php
  4. 10 core/modules/views/src/Plugin/views/argument/Date.php
  5. 10 core/modules/datetime/src/Plugin/views/sort/Date.php
  6. 10 core/modules/datetime/src/Plugin/views/filter/Date.php
  7. 10 core/lib/Drupal/Core/Render/Element/Date.php
Same filename in other branches
  1. 9 core/modules/views/src/Plugin/views/sort/Date.php
  2. 9 core/modules/views/src/Plugin/views/field/Date.php
  3. 9 core/modules/views/src/Plugin/views/filter/Date.php
  4. 9 core/modules/views/src/Plugin/views/argument/Date.php
  5. 9 core/modules/datetime/src/Plugin/views/sort/Date.php
  6. 9 core/modules/datetime/src/Plugin/views/filter/Date.php
  7. 9 core/modules/datetime/src/Plugin/views/argument/Date.php
  8. 9 core/lib/Drupal/Core/Render/Element/Date.php
  9. 8.9.x core/modules/views/src/Plugin/views/sort/Date.php
  10. 8.9.x core/modules/views/src/Plugin/views/field/Date.php
  11. 8.9.x core/modules/views/src/Plugin/views/filter/Date.php
  12. 8.9.x core/modules/views/src/Plugin/views/argument/Date.php
  13. 8.9.x core/modules/datetime/src/Plugin/views/sort/Date.php
  14. 8.9.x core/modules/datetime/src/Plugin/views/filter/Date.php
  15. 8.9.x core/modules/datetime/src/Plugin/views/argument/Date.php
  16. 8.9.x core/lib/Drupal/Core/Render/Element/Date.php
  17. 11.x core/modules/views/src/Plugin/views/sort/Date.php
  18. 11.x core/modules/views/src/Plugin/views/field/Date.php
  19. 11.x core/modules/views/src/Plugin/views/filter/Date.php
  20. 11.x core/modules/views/src/Plugin/views/argument/Date.php
  21. 11.x core/modules/datetime/src/Plugin/views/sort/Date.php
  22. 11.x core/modules/datetime/src/Plugin/views/filter/Date.php
  23. 11.x core/modules/datetime/src/Plugin/views/argument/Date.php
  24. 11.x core/lib/Drupal/Core/Render/Element/Date.php

Namespace

Drupal\datetime\Plugin\views\argument

File

core/modules/datetime/src/Plugin/views/argument/Date.php

View source
<?php

namespace Drupal\datetime\Plugin\views\argument;

use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\views\Attribute\ViewsArgument;
use Drupal\views\FieldAPIHandlerTrait;
use Drupal\views\Plugin\views\argument\Date as NumericDate;

/**
 * Abstract argument handler for dates.
 *
 * Adds an option to set a default argument based on the current date.
 *
 * Definitions terms:
 * - many to one: If true, the "many to one" helper will be used.
 * - invalid input: A string to give to the user for obviously invalid input.
 *                  This is deprecated in favor of argument validators.
 *
 * @see \Drupal\views\ManyToOneHelper
 *
 * @ingroup views_argument_handlers
 */
class Date extends NumericDate {
    use FieldAPIHandlerTrait;
    
    /**
     * Determines if the timezone offset is calculated.
     *
     * @var bool
     */
    protected $calculateOffset = TRUE;
    
    /**
     * {@inheritdoc}
     */
    public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match, DateFormatterInterface $date_formatter, ?TimeInterface $time = NULL) {
        if (!$time) {
            @trigger_error('Calling ' . __METHOD__ . ' without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3395991', E_USER_DEPRECATED);
            $time = \Drupal::service('datetime.time');
        }
        parent::__construct($configuration, $plugin_id, $plugin_definition, $route_match, $date_formatter, $time);
        $definition = $this->getFieldStorageDefinition();
        if ($definition->getSetting('datetime_type') === DateTimeItem::DATETIME_TYPE_DATE) {
            // Timezone offset calculation is not applicable to dates that are stored
            // as date-only.
            $this->calculateOffset = FALSE;
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDateField() {
        // Use string date storage/formatting since datetime fields are stored as
        // strings rather than UNIX timestamps.
        return $this->query
            ->getDateField("{$this->tableAlias}.{$this->realField}", TRUE, $this->calculateOffset);
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDateFormat($format) {
        // Pass in the string-field option.
        return $this->query
            ->getDateFormat($this->getDateField(), $format, TRUE);
    }

}

Classes

Title Deprecated Summary
Date Abstract argument handler for dates.

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