class Date

Same name in this branch
  1. 9 core/modules/views/src/Plugin/views/sort/Date.php \Drupal\views\Plugin\views\sort\Date
  2. 9 core/modules/views/src/Plugin/views/field/Date.php \Drupal\views\Plugin\views\field\Date
  3. 9 core/modules/views/src/Plugin/views/filter/Date.php \Drupal\views\Plugin\views\filter\Date
  4. 9 core/modules/views/src/Plugin/views/argument/Date.php \Drupal\views\Plugin\views\argument\Date
  5. 9 core/modules/datetime/src/Plugin/views/sort/Date.php \Drupal\datetime\Plugin\views\sort\Date
  6. 9 core/modules/datetime/src/Plugin/views/filter/Date.php \Drupal\datetime\Plugin\views\filter\Date
  7. 9 core/lib/Drupal/Core/Render/Element/Date.php \Drupal\Core\Render\Element\Date
Same name and namespace in other branches
  1. 11.x core/modules/views/src/Plugin/views/sort/Date.php \Drupal\views\Plugin\views\sort\Date
  2. 11.x core/modules/views/src/Plugin/views/field/Date.php \Drupal\views\Plugin\views\field\Date
  3. 11.x core/modules/views/src/Plugin/views/filter/Date.php \Drupal\views\Plugin\views\filter\Date
  4. 11.x core/modules/views/src/Plugin/views/argument/Date.php \Drupal\views\Plugin\views\argument\Date
  5. 11.x core/modules/datetime/src/Plugin/views/sort/Date.php \Drupal\datetime\Plugin\views\sort\Date
  6. 11.x core/modules/datetime/src/Plugin/views/filter/Date.php \Drupal\datetime\Plugin\views\filter\Date
  7. 11.x core/modules/datetime/src/Plugin/views/argument/Date.php \Drupal\datetime\Plugin\views\argument\Date
  8. 11.x core/lib/Drupal/Core/Render/Element/Date.php \Drupal\Core\Render\Element\Date

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.

Plugin annotation

@ViewsArgument("datetime");

Hierarchy

Expanded class hierarchy of Date

See also

\Drupal\views\ManyToOneHelper

Related topics

168 string references to 'Date'
Callbacks::dateCallback in core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php
Ajax callback triggered by date.
CallbackTest::providerCallbackArray in core/modules/migrate/tests/src/Unit/process/CallbackTest.php
Data provider for ::testCallbackArray().
claro_preprocess_input in core/themes/claro/claro.theme
Implements template_preprocess_HOOK() for input.
CommentAccessControlHandler::checkFieldAccess in core/modules/comment/src/CommentAccessControlHandler.php
CommentForm::buildEntity in core/modules/comment/src/CommentForm.php
Builds an updated entity object based upon the submitted form values.

... See full list

File

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

Namespace

Drupal\datetime\Plugin\views\argument
View source
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) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $route_match, $date_formatter);
    $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);
  }

}

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