Commit 0107faaf authored by webchick's avatar webchick
Browse files

Issue #1965842 by dawehner: Move date argument annotations to properties.

parent fc6a9aeb
......@@ -19,20 +19,31 @@
* - 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.
* - arg_format: The format string to use on the current time when dealing with
* date values.
*
* @see Drupal\views\ManyTonOneHelper
*
* @ingroup views_argument_handlers
*
* @Plugin(
* id = "date",
* arg_format = "Y-m-d"
* id = "date"
* )
*/
class Date extends Formula {
/**
* The date format used in the title.
*
* @var string
*/
protected $format;
/**
* The date format used in the query.
*
* @var string
*/
protected $argFormat = 'Y-m-d';
var $option_name = 'default_argument_date';
/**
......@@ -50,7 +61,7 @@ function default_argument_form(&$form, &$form_state) {
*/
function get_default_argument($raw = FALSE) {
if (!$raw && $this->options['default_argument_type'] == 'date') {
return date($this->definition['format'], REQUEST_TIME);
return date($this->argFormat, REQUEST_TIME);
}
elseif (!$raw && in_array($this->options['default_argument_type'], array('node_created', 'node_changed'))) {
foreach (range(1, 3) as $i) {
......@@ -68,10 +79,10 @@ function get_default_argument($raw = FALSE) {
return parent::get_default_argument();
}
elseif ($this->options['default_argument_type'] == 'node_created') {
return date($this->definition['format'], $node->created);
return date($this->argFormat, $node->created);
}
elseif ($this->options['default_argument_type'] == 'node_changed') {
return date($this->definition['format'], $node->changed);
return date($this->argFormat, $node->changed);
}
}
......@@ -86,7 +97,7 @@ function get_sort_name() {
* Overrides \Drupal\views\Plugin\views\argument\Formula::get_formula().
*/
function get_formula() {
$this->formula = $this->getDateFormat($this->definition['arg_format']);
$this->formula = $this->getDateFormat($this->argFormat);
return parent::get_formula();
}
......
......@@ -14,20 +14,28 @@
*
* @Plugin(
* id = "date_day",
* arg_format = "d",
* format = "j",
* module = "views"
* )
*/
class DayDate extends Date {
/**
* {@inheritdoc}
*/
protected $format = 'j';
/**
* {@inheritdoc}
*/
protected $argFormat = 'd';
/**
* Provide a link to the next level of the view
*/
function summary_name($data) {
$day = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT);
// strtotime respects server timezone, so we need to set the time fixed as utc time
return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->definition['format'], 'UTC');
return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
/**
......@@ -35,7 +43,7 @@ function summary_name($data) {
*/
function title() {
$day = str_pad($this->argument, 2, '0', STR_PAD_LEFT);
return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->definition['format'], 'UTC');
return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
function summary_argument($data) {
......
......@@ -14,26 +14,34 @@
*
* @Plugin(
* id = "date_fulldate",
* arg_format = "Ymd",
* format = "F j, Y",
* module = "views"
* )
*/
class FullDate extends Date {
/**
* {@inheritdoc}
*/
protected $format = 'F j, Y';
/**
* {@inheritdoc}
*/
protected $argFormat = 'Ymd';
/**
* Provide a link to the next level of the view
*/
function summary_name($data) {
$created = $data->{$this->name_alias};
return format_date(strtotime($created . " 00:00:00 UTC"), 'custom', $this->definition['format'], 'UTC');
return format_date(strtotime($created . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
/**
* Provide a link to the next level of the view
*/
function title() {
return format_date(strtotime($this->argument . " 00:00:00 UTC"), 'custom', $this->definition['format'], 'UTC');
return format_date(strtotime($this->argument . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
}
......@@ -14,19 +14,27 @@
*
* @Plugin(
* id = "date_month",
* arg_format = "m",
* format = "F",
* module = "views"
* )
*/
class MonthDate extends Date {
/**
* {@inheritdoc}
*/
protected $format = 'F';
/**
* {@inheritdoc}
*/
protected $argFormat = 'm';
/**
* Provide a link to the next level of the view
*/
function summary_name($data) {
$month = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT);
return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC" ), 'custom', $this->definition['format'], 'UTC');
return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC" ), 'custom', $this->format, 'UTC');
}
/**
......@@ -34,7 +42,7 @@ function summary_name($data) {
*/
function title() {
$month = str_pad($this->argument, 2, '0', STR_PAD_LEFT);
return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC"), 'custom', $this->definition['format'], 'UTC');
return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
function summary_argument($data) {
......
......@@ -14,12 +14,16 @@
*
* @Plugin(
* id = "date_week",
* arg_format = "W",
* module = "views"
* )
*/
class WeekDate extends Date {
/**
* {@inheritdoc}
*/
protected $argFormat = 'W';
/**
* Provide a link to the next level of the view
*/
......
......@@ -14,10 +14,14 @@
*
* @Plugin(
* id = "date_year",
* arg_format = "Y",
* module = "views"
* )
*/
class YearDate extends Date {
/**
* {@inheritdoc}
*/
protected $argFormat = 'Y';
}
......@@ -14,26 +14,34 @@
*
* @Plugin(
* id = "date_year_month",
* format = "F Y",
* arg_format = "Ym",
* module = "views"
* )
*/
class YearMonthDate extends Date {
/**
* {@inheritdoc}
*/
protected $format = 'F Y';
/**
* {@inheritdoc}
*/
protected $argFormat = 'Ym';
/**
* Provide a link to the next level of the view
*/
function summary_name($data) {
$created = $data->{$this->name_alias};
return format_date(strtotime($created . "15" . " 00:00:00 UTC"), 'custom', $this->definition['format'], 'UTC');
return format_date(strtotime($created . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
/**
* Provide a link to the next level of the view
*/
function title() {
return format_date(strtotime($this->argument . "15" . " 00:00:00 UTC"), 'custom', $this->definition['format'], 'UTC');
return format_date(strtotime($this->argument . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment