Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542
This commit is contained in:
parent
3b2511d96d
commit
81ccda77eb
2155 changed files with 54307 additions and 46870 deletions
45
core/modules/datetime/src/Plugin/views/argument/Date.php
Normal file
45
core/modules/datetime/src/Plugin/views/argument/Date.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\views\Argument\Date.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\views\Argument;
|
||||
|
||||
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\ManyTonOneHelper
|
||||
*
|
||||
* @ingroup views_argument_handlers
|
||||
*
|
||||
* @ViewsArgument("datetime")
|
||||
*/
|
||||
class Date extends NumericDate {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDateField() {
|
||||
// Return the real field, since it is already in string format.
|
||||
return "$this->tableAlias.$this->realField";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDateFormat($format) {
|
||||
// Pass in the string-field option.
|
||||
return $this->query->getDateFormat($this->getDateField(), $format, TRUE);
|
||||
}
|
||||
}
|
||||
22
core/modules/datetime/src/Plugin/views/argument/DayDate.php
Normal file
22
core/modules/datetime/src/Plugin/views/argument/DayDate.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\views\argument\DayDate.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\views\argument;
|
||||
|
||||
/**
|
||||
* Argument handler for a day.
|
||||
*
|
||||
* @ViewsArgument("datetime_day")
|
||||
*/
|
||||
class DayDate extends Date {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $argFormat = 'd';
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\views\argument\MonthDate.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\views\argument;
|
||||
|
||||
/**
|
||||
* Argument handler for a month.
|
||||
*
|
||||
* @ViewsArgument("datetime_month")
|
||||
*/
|
||||
class MonthDate extends Date {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $argFormat = 'm';
|
||||
|
||||
}
|
||||
22
core/modules/datetime/src/Plugin/views/argument/YearDate.php
Normal file
22
core/modules/datetime/src/Plugin/views/argument/YearDate.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\views\argument\YearDate.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\views\argument;
|
||||
|
||||
/**
|
||||
* Argument handler for a year.
|
||||
*
|
||||
* @ViewsArgument("datetime_year")
|
||||
*/
|
||||
class YearDate extends Date {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $argFormat = 'Y';
|
||||
|
||||
}
|
||||
131
core/modules/datetime/src/Plugin/views/filter/Date.php
Normal file
131
core/modules/datetime/src/Plugin/views/filter/Date.php
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\views\filter\Date.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\views\filter;
|
||||
|
||||
use Drupal\Core\Datetime\DateFormatter;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
|
||||
use Drupal\views\FieldAPIHandlerTrait;
|
||||
use Drupal\views\Plugin\views\filter\Date as NumericDate;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
* Date/time views filter.
|
||||
*
|
||||
* Even thought dates are stored as strings, the numeric filter is extended
|
||||
* because it provides more sensible operators.
|
||||
*
|
||||
* @ingroup views_filter_handlers
|
||||
*
|
||||
* @ViewsFilter("datetime")
|
||||
*/
|
||||
class Date extends NumericDate implements ContainerFactoryPluginInterface {
|
||||
|
||||
use FieldAPIHandlerTrait;
|
||||
|
||||
/**
|
||||
* The date formatter service.
|
||||
*
|
||||
* @var \Drupal\Core\Datetime\DateFormatter
|
||||
*/
|
||||
protected $dateFormatter;
|
||||
|
||||
/**
|
||||
* Date format for SQL conversion.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @see \Drupal\views\Plugin\views\query\Sql::getDateFormat()
|
||||
*/
|
||||
protected $dateFormat = DATETIME_DATETIME_STORAGE_FORMAT;
|
||||
|
||||
/**
|
||||
* The request stack used to determin current time.
|
||||
*
|
||||
* @var \Symfony\Component\HttpFoundation\RequestStack
|
||||
*/
|
||||
protected $requestStack;
|
||||
|
||||
/**
|
||||
* Constructs a new Date handler.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin ID for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Datetime\DateFormatter $date_formatter
|
||||
* The date formatter service.
|
||||
* @param \Symfony\Component\HttpFoundation\RequestStack
|
||||
* The request stack used to determine the current time.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, DateFormatter $date_formatter, RequestStack $request_stack) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->dateFormatter = $date_formatter;
|
||||
$this->requestStack = $request_stack;
|
||||
|
||||
// Date format depends on field storage format.
|
||||
$definition = $this->getFieldStorageDefinition();
|
||||
if ($definition->getSetting('datetime_type') === DateTimeItem::DATETIME_TYPE_DATE) {
|
||||
$this->dateFormat = DATETIME_DATE_STORAGE_FORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('date.formatter'),
|
||||
$container->get('request_stack')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override parent method, which deals with dates as integers.
|
||||
*/
|
||||
protected function opBetween($field) {
|
||||
$origin = ($this->value['type'] == 'offset') ? $this->requestStack->getCurrentRequest()->server->get('REQUEST_TIME') : 0;
|
||||
$a = intval(strtotime($this->value['min'], $origin));
|
||||
$b = intval(strtotime($this->value['max'], $origin));
|
||||
|
||||
// Formatting will vary on date storage.
|
||||
|
||||
|
||||
// Convert to ISO format and format for query. UTC timezone is used since
|
||||
// dates are stored in UTC.
|
||||
$a = $this->query->getDateFormat("'" . $this->dateFormatter->format($a, 'custom', DATETIME_DATETIME_STORAGE_FORMAT, DATETIME_STORAGE_TIMEZONE) . "'", $this->dateFormat, TRUE);
|
||||
$b = $this->query->getDateFormat("'" . $this->dateFormatter->format($b, 'custom', DATETIME_DATETIME_STORAGE_FORMAT, DATETIME_STORAGE_TIMEZONE) . "'", $this->dateFormat, TRUE);
|
||||
|
||||
// This is safe because we are manually scrubbing the values.
|
||||
$operator = strtoupper($this->operator);
|
||||
$field = $this->query->getDateFormat($field, $this->dateFormat, TRUE);
|
||||
$this->query->addWhereExpression($this->options['group'], "$field $operator $a AND $b");
|
||||
}
|
||||
|
||||
/**
|
||||
* Override parent method, which deals with dates as integers.
|
||||
*/
|
||||
protected function opSimple($field) {
|
||||
$origin = (!empty($this->value['type']) && $this->value['type'] == 'offset') ? $this->requestStack->getCurrentRequest()->server->get('REQUEST_TIME') : 0;
|
||||
$value = intval(strtotime($this->value['value'], $origin));
|
||||
|
||||
// Convert to ISO. UTC is used since dates are stored in UTC.
|
||||
$value = $this->query->getDateFormat("'" . $this->dateFormatter->format($value, 'custom', DATETIME_DATETIME_STORAGE_FORMAT, DATETIME_STORAGE_TIMEZONE) . "'", $this->dateFormat, TRUE);
|
||||
|
||||
// This is safe because we are manually scrubbing the value.
|
||||
$field = $this->query->getDateFormat($field, $this->dateFormat, TRUE);
|
||||
$this->query->addWhereExpression($this->options['group'], "$field $this->operator $value");
|
||||
}
|
||||
|
||||
}
|
||||
56
core/modules/datetime/src/Plugin/views/sort/Date.php
Normal file
56
core/modules/datetime/src/Plugin/views/sort/Date.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\views\sort\Date.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\views\sort;
|
||||
|
||||
use Drupal\views\Plugin\views\sort\Date as NumericDate;
|
||||
|
||||
/**
|
||||
* Basic sort handler for datetime fields.
|
||||
*
|
||||
* This handler enables granularity, which is the ability to make dates
|
||||
* equivalent based upon nearness.
|
||||
*
|
||||
* @ViewsSort("datetime")
|
||||
*/
|
||||
class Date extends NumericDate {
|
||||
|
||||
/**
|
||||
* Override to account for dates stored as strings.
|
||||
*/
|
||||
public function getDateField() {
|
||||
// Return the real field, since it is already in string format.
|
||||
return "$this->tableAlias.$this->realField";
|
||||
}
|
||||
|
||||
/**
|
||||
* Override query to provide 'second' granularity.
|
||||
*/
|
||||
public function query() {
|
||||
$this->ensureMyTable();
|
||||
switch ($this->options['granularity']) {
|
||||
case 'second':
|
||||
$formula = $this->getDateFormat('YmdHis');
|
||||
$this->query->addOrderBy(NULL, $formula, $this->options['order'], $this->tableAlias . '_' . $this->field . '_' . $this->options['granularity']);
|
||||
return;
|
||||
}
|
||||
|
||||
// All other granularities are handled by the numeric sort handler.
|
||||
parent::query();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Overridden in order to pass in the string date flag.
|
||||
*/
|
||||
public function getDateFormat($format) {
|
||||
return $this->query->getDateFormat($this->getDateField(), $format, TRUE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in a new issue