upgrades core to 8.4.2

This commit is contained in:
Bachir Soussi Chiadmi
2017-11-14 16:09:54 +01:00
parent bd60eff9b3
commit c2b4e25be4
3504 changed files with 140306 additions and 38684 deletions
@@ -32,30 +32,18 @@ class DateTimeCustomFormatter extends DateTimeFormatterBase {
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
// @todo Evaluate removing this method in
// https://www.drupal.org/node/2793143 to determine if the behavior and
// markup in the base class implementation can be used instead.
$elements = [];
foreach ($items as $delta => $item) {
$output = '';
if (!empty($item->date)) {
/** @var \Drupal\Core\Datetime\DrupalDateTime $date */
$date = $item->date;
if ($this->getFieldSetting('datetime_type') == 'date') {
// A date without time will pick up the current time, use the default.
datetime_date_default_time($date);
}
$this->setTimeZone($date);
$output = $this->formatDate($date);
$elements[$delta] = $this->buildDate($date);
}
$elements[$delta] = [
'#markup' => $output,
'#cache' => [
'contexts' => [
'timezone',
],
],
];
}
return $elements;
@@ -3,7 +3,6 @@
namespace Drupal\datetime\Plugin\Field\FieldFormatter;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
/**
@@ -28,59 +27,6 @@ class DateTimeDefaultFormatter extends DateTimeFormatterBase {
] + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
$output = '';
$iso_date = '';
if ($item->date) {
/** @var \Drupal\Core\Datetime\DrupalDateTime $date */
$date = $item->date;
if ($this->getFieldSetting('datetime_type') == 'date') {
// A date without time will pick up the current time, use the default.
datetime_date_default_time($date);
}
// Create the ISO date in Universal Time.
$iso_date = $date->format("Y-m-d\TH:i:s") . 'Z';
$this->setTimeZone($date);
$output = $this->formatDate($date);
}
// Display the date using theme datetime.
$elements[$delta] = [
'#cache' => [
'contexts' => [
'timezone',
],
],
'#theme' => 'time',
'#text' => $output,
'#html' => FALSE,
'#attributes' => [
'datetime' => $iso_date,
],
];
if (!empty($item->_attributes)) {
$elements[$delta]['#attributes'] += $item->_attributes;
// Unset field item attributes since they have been included in the
// formatter output and should not be rendered in the field template.
unset($item->_attributes);
}
}
return $elements;
}
/**
* {@inheritdoc}
*/
@@ -122,7 +68,7 @@ class DateTimeDefaultFormatter extends DateTimeFormatterBase {
$summary = parent::settingsSummary();
$date = new DrupalDateTime();
$summary[] = t('Format: @display', ['@display' => $this->formatDate($date, $this->getFormatSettings())]);
$summary[] = t('Format: @display', ['@display' => $this->formatDate($date)]);
return $summary;
}
@@ -6,13 +6,13 @@ use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Base class for 'DateTime Field formatter' plugin implementations.
*/
@@ -97,7 +97,7 @@ abstract class DateTimeFormatterBase extends FormatterBase implements ContainerF
'#type' => 'select',
'#title' => $this->t('Time zone override'),
'#description' => $this->t('The time zone selected here will always be used'),
'#options' => system_time_zones(TRUE),
'#options' => system_time_zones(TRUE, TRUE),
'#default_value' => $this->getSetting('timezone_override'),
];
@@ -117,6 +117,30 @@ abstract class DateTimeFormatterBase extends FormatterBase implements ContainerF
return $summary;
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
if ($item->date) {
/** @var \Drupal\Core\Datetime\DrupalDateTime $date */
$date = $item->date;
$elements[$delta] = $this->buildDateWithIsoAttribute($date);
if (!empty($item->_attributes)) {
$elements[$delta]['#attributes'] += $item->_attributes;
// Unset field item attributes since they have been included in the
// formatter output and should not be rendered in the field template.
unset($item->_attributes);
}
}
}
return $elements;
}
/**
* Creates a formatted date value as a string.
*
@@ -167,4 +191,69 @@ abstract class DateTimeFormatterBase extends FormatterBase implements ContainerF
return $settings;
}
/**
* Creates a render array from a date object.
*
* @param \Drupal\Core\Datetime\DrupalDateTime $date
* A date object.
*
* @return array
* A render array.
*/
protected function buildDate(DrupalDateTime $date) {
if ($this->getFieldSetting('datetime_type') == DateTimeItem::DATETIME_TYPE_DATE) {
// A date without time will pick up the current time, use the default.
datetime_date_default_time($date);
}
$this->setTimeZone($date);
$build = [
'#markup' => $this->formatDate($date),
'#cache' => [
'contexts' => [
'timezone',
],
],
];
return $build;
}
/**
* Creates a render array from a date object with ISO date attribute.
*
* @param \Drupal\Core\Datetime\DrupalDateTime $date
* A date object.
*
* @return array
* A render array.
*/
protected function buildDateWithIsoAttribute(DrupalDateTime $date) {
if ($this->getFieldSetting('datetime_type') == DateTimeItem::DATETIME_TYPE_DATE) {
// A date without time will pick up the current time, use the default.
datetime_date_default_time($date);
}
// Create the ISO date in Universal Time.
$iso_date = $date->format("Y-m-d\TH:i:s") . 'Z';
$this->setTimeZone($date);
$build = [
'#theme' => 'time',
'#text' => $this->formatDate($date),
'#html' => FALSE,
'#attributes' => [
'datetime' => $iso_date,
],
'#cache' => [
'contexts' => [
'timezone',
],
],
];
return $build;
}
}
@@ -25,27 +25,12 @@ class DateTimePlainFormatter extends DateTimeFormatterBase {
$elements = [];
foreach ($items as $delta => $item) {
$output = '';
if (!empty($item->date)) {
/** @var \Drupal\Core\Datetime\DrupalDateTime $date */
$date = $item->date;
if ($this->getFieldSetting('datetime_type') == 'date') {
// A date without time will pick up the current time, use the default.
datetime_date_default_time($date);
}
$this->setTimeZone($date);
$output = $this->formatDate($date);
$elements[$delta] = $this->buildDate($date);
}
$elements[$delta] = [
'#cache' => [
'contexts' => [
'timezone',
],
],
'#markup' => $output,
];
}
return $elements;
@@ -17,7 +17,8 @@ use Drupal\Core\Field\FieldItemBase;
* description = @Translation("Create and store date values."),
* default_widget = "datetime_default",
* default_formatter = "datetime_default",
* list_class = "\Drupal\datetime\Plugin\Field\FieldType\DateTimeFieldItemList"
* list_class = "\Drupal\datetime\Plugin\Field\FieldType\DateTimeFieldItemList",
* constraints = {"DateTimeFormat" = {}}
* )
*/
class DateTimeItem extends FieldItemBase {
@@ -0,0 +1,38 @@
<?php
namespace Drupal\datetime\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
/**
* Validation constraint for DateTime items to ensure the format is correct.
*
* @Constraint(
* id = "DateTimeFormat",
* label = @Translation("Datetime format valid for datetime type.", context = "Validation"),
* )
*/
class DateTimeFormatConstraint extends Constraint {
/**
* Message for when the value isn't a string.
*
* @var string
*/
public $badType = "The datetime value must be a string.";
/**
* Message for when the value isn't in the proper format.
*
* @var string
*/
public $badFormat = "The datetime value '@value' is invalid for the format '@format'";
/**
* Message for when the value did not parse properly.
*
* @var string
*/
public $badValue = "The datetime value '@value' did not parse properly for the format '@format'";
}
@@ -0,0 +1,56 @@
<?php
namespace Drupal\datetime\Plugin\Validation\Constraint;
use Drupal\Component\Datetime\DateTimePlus;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* Constraint validator for DateTime items to ensure the format is correct.
*/
class DateTimeFormatConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($item, Constraint $constraint) {
/* @var $item \Drupal\datetime\Plugin\Field\FieldType\DateTimeItem */
if (isset($item)) {
$value = $item->getValue()['value'];
if (!is_string($value)) {
$this->context->addViolation($constraint->badType);
}
else {
$datetime_type = $item->getFieldDefinition()->getSetting('datetime_type');
$format = $datetime_type === DateTimeItem::DATETIME_TYPE_DATE ? DATETIME_DATE_STORAGE_FORMAT : DATETIME_DATETIME_STORAGE_FORMAT;
$date = NULL;
try {
$date = DateTimePlus::createFromFormat($format, $value, new \DateTimeZone(DATETIME_STORAGE_TIMEZONE));
}
catch (\InvalidArgumentException $e) {
$this->context->addViolation($constraint->badFormat, [
'@value' => $value,
'@format' => $format,
]);
return;
}
catch (\UnexpectedValueException $e) {
$this->context->addViolation($constraint->badValue, [
'@value' => $value,
'@format' => $format,
]);
return;
}
if ($date === NULL || $date->hasErrors()) {
$this->context->addViolation($constraint->badFormat, [
'@value' => $value,
'@format' => $format,
]);
}
}
}
}
}
@@ -0,0 +1,70 @@
<?php
namespace Drupal\datetime\Plugin\migrate\field;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateException;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
/**
* @MigrateField(
* id = "datetime",
* type_map = {
* "date" = "datetime",
* "datestamp" = "timestamp",
* "datetime" = "datetime",
* },
* core = {6,7}
* )
*/
class DateField extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldWidgetMap() {
return [
'date' => 'datetime_default',
'datetime' => 'datetime_default',
'datestamp' => 'datetime_timestamp',
];
}
/**
* {@inheritdoc}
*/
public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
switch ($data['type']) {
case 'date':
$from_format = 'Y-m-d\TH:i:s';
$to_format = 'Y-m-d\TH:i:s';
break;
case 'datestamp':
$from_format = 'U';
$to_format = 'U';
break;
case 'datetime':
$from_format = 'Y-m-d H:i:s';
$to_format = 'Y-m-d\TH:i:s';
break;
default:
throw new MigrateException(sprintf('Field %s of type %s is an unknown date field type.', $field_name, var_export($data['type'], TRUE)));
}
$process = [
'value' => [
'plugin' => 'format_date',
'from_format' => $from_format,
'to_format' => $to_format,
'source' => 'value',
],
];
$process = [
'plugin' => 'iterator',
'source' => $field_name,
'process' => $process,
];
$migration->mergeProcessOfProperty($field_name, $process);
}
}
@@ -2,6 +2,8 @@
namespace Drupal\datetime\Plugin\migrate\field\d6;
@trigger_error('DateField is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\datetime\Plugin\migrate\field\DateField instead.', E_USER_DEPRECATED);
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateException;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
@@ -16,6 +18,9 @@ use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
* },
* core = {6}
* )
*
* @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use
* \Drupal\datetime\Plugin\migrate\field\DateField instead.
*/
class DateField extends FieldPluginBase {
@@ -30,15 +35,6 @@ class DateField extends FieldPluginBase {
];
}
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
// See d6_field_formatter_settings.yml and
// FieldPluginBase::processFieldFormatter().
return [];
}
/**
* {@inheritdoc}
*/
@@ -1,6 +1,6 @@
<?php
namespace Drupal\datetime\Plugin\views\Argument;
namespace Drupal\datetime\Plugin\views\argument;
use Drupal\views\Plugin\views\argument\Date as NumericDate;
@@ -2,6 +2,8 @@
namespace Drupal\datetime\Tests\Views;
@trigger_error('\Drupal\datetime\Tests\Views\DateTimeHandlerTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\BrowserTestBase', E_USER_DEPRECATED);
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\NodeType;
@@ -11,6 +13,9 @@ use Drupal\field\Entity\FieldStorageConfig;
/**
* Base class for testing datetime handlers.
*
* @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
* Use \Drupal\Tests\BrowserTestBase.
*/
abstract class DateTimeHandlerTestBase extends HandlerTestBase {