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

8.0.x
webchick 2013-04-10 10:32:15 -07:00
parent fc6a9aeb00
commit 0107faaffd
7 changed files with 77 additions and 26 deletions

View File

@ -19,20 +19,31 @@ use Drupal\Core\Database\Database;
* - many to one: If true, the "many to one" helper will be used. * - 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. * - invalid input: A string to give to the user for obviously invalid input.
* This is deprecated in favor of argument validators. * 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 * @see Drupal\views\ManyTonOneHelper
* *
* @ingroup views_argument_handlers * @ingroup views_argument_handlers
* *
* @Plugin( * @Plugin(
* id = "date", * id = "date"
* arg_format = "Y-m-d"
* ) * )
*/ */
class Date extends Formula { 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'; var $option_name = 'default_argument_date';
/** /**
@ -50,7 +61,7 @@ class Date extends Formula {
*/ */
function get_default_argument($raw = FALSE) { function get_default_argument($raw = FALSE) {
if (!$raw && $this->options['default_argument_type'] == 'date') { 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'))) { elseif (!$raw && in_array($this->options['default_argument_type'], array('node_created', 'node_changed'))) {
foreach (range(1, 3) as $i) { foreach (range(1, 3) as $i) {
@ -68,10 +79,10 @@ class Date extends Formula {
return parent::get_default_argument(); return parent::get_default_argument();
} }
elseif ($this->options['default_argument_type'] == 'node_created') { 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') { 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 @@ class Date extends Formula {
* Overrides \Drupal\views\Plugin\views\argument\Formula::get_formula(). * Overrides \Drupal\views\Plugin\views\argument\Formula::get_formula().
*/ */
function get_formula() { function get_formula() {
$this->formula = $this->getDateFormat($this->definition['arg_format']); $this->formula = $this->getDateFormat($this->argFormat);
return parent::get_formula(); return parent::get_formula();
} }

View File

@ -14,20 +14,28 @@ use Drupal\Component\Annotation\Plugin;
* *
* @Plugin( * @Plugin(
* id = "date_day", * id = "date_day",
* arg_format = "d",
* format = "j",
* module = "views" * module = "views"
* ) * )
*/ */
class DayDate extends Date { class DayDate extends Date {
/**
* {@inheritdoc}
*/
protected $format = 'j';
/**
* {@inheritdoc}
*/
protected $argFormat = 'd';
/** /**
* Provide a link to the next level of the view * Provide a link to the next level of the view
*/ */
function summary_name($data) { function summary_name($data) {
$day = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT); $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 // 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 @@ class DayDate extends Date {
*/ */
function title() { function title() {
$day = str_pad($this->argument, 2, '0', STR_PAD_LEFT); $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) { function summary_argument($data) {

View File

@ -14,26 +14,34 @@ use Drupal\Component\Annotation\Plugin;
* *
* @Plugin( * @Plugin(
* id = "date_fulldate", * id = "date_fulldate",
* arg_format = "Ymd",
* format = "F j, Y",
* module = "views" * module = "views"
* ) * )
*/ */
class FullDate extends Date { class FullDate extends Date {
/**
* {@inheritdoc}
*/
protected $format = 'F j, Y';
/**
* {@inheritdoc}
*/
protected $argFormat = 'Ymd';
/** /**
* Provide a link to the next level of the view * Provide a link to the next level of the view
*/ */
function summary_name($data) { function summary_name($data) {
$created = $data->{$this->name_alias}; $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 * Provide a link to the next level of the view
*/ */
function title() { 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');
} }
} }

View File

@ -14,19 +14,27 @@ use Drupal\Component\Annotation\Plugin;
* *
* @Plugin( * @Plugin(
* id = "date_month", * id = "date_month",
* arg_format = "m",
* format = "F",
* module = "views" * module = "views"
* ) * )
*/ */
class MonthDate extends Date { class MonthDate extends Date {
/**
* {@inheritdoc}
*/
protected $format = 'F';
/**
* {@inheritdoc}
*/
protected $argFormat = 'm';
/** /**
* Provide a link to the next level of the view * Provide a link to the next level of the view
*/ */
function summary_name($data) { function summary_name($data) {
$month = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT); $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 @@ class MonthDate extends Date {
*/ */
function title() { function title() {
$month = str_pad($this->argument, 2, '0', STR_PAD_LEFT); $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) { function summary_argument($data) {

View File

@ -14,12 +14,16 @@ use Drupal\Component\Annotation\Plugin;
* *
* @Plugin( * @Plugin(
* id = "date_week", * id = "date_week",
* arg_format = "W",
* module = "views" * module = "views"
* ) * )
*/ */
class WeekDate extends Date { class WeekDate extends Date {
/**
* {@inheritdoc}
*/
protected $argFormat = 'W';
/** /**
* Provide a link to the next level of the view * Provide a link to the next level of the view
*/ */

View File

@ -14,10 +14,14 @@ use Drupal\Component\Annotation\Plugin;
* *
* @Plugin( * @Plugin(
* id = "date_year", * id = "date_year",
* arg_format = "Y",
* module = "views" * module = "views"
* ) * )
*/ */
class YearDate extends Date { class YearDate extends Date {
/**
* {@inheritdoc}
*/
protected $argFormat = 'Y';
} }

View File

@ -14,26 +14,34 @@ use Drupal\Component\Annotation\Plugin;
* *
* @Plugin( * @Plugin(
* id = "date_year_month", * id = "date_year_month",
* format = "F Y",
* arg_format = "Ym",
* module = "views" * module = "views"
* ) * )
*/ */
class YearMonthDate extends Date { class YearMonthDate extends Date {
/**
* {@inheritdoc}
*/
protected $format = 'F Y';
/**
* {@inheritdoc}
*/
protected $argFormat = 'Ym';
/** /**
* Provide a link to the next level of the view * Provide a link to the next level of the view
*/ */
function summary_name($data) { function summary_name($data) {
$created = $data->{$this->name_alias}; $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 * Provide a link to the next level of the view
*/ */
function title() { 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');
} }
} }