Commit 98060490 authored by alexpott's avatar alexpott
Browse files

Issue #2006484 by tim.plunkett, dawehner: Remove dependency on datetime from node.

parent fd9804d8
......@@ -9,6 +9,7 @@
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Template\Attribute;
use Drupal\datetime\DateHelper;
use Drupal\node\NodeInterface;
/**
* Defines the timezone that dates should be stored in.
......@@ -1120,3 +1121,23 @@ function datetime_range_years($string, $date = NULL) {
}
return array($min_year, $max_year);
}
/**
* Implements hook_form_BASE_FORM_ID_alter() for node forms.
*/
function datetime_form_node_form_alter(&$form, &$form_state, $form_id) {
// Alter the 'Authored on' date to use datetime.
$form['author']['date']['#type'] = 'datetime';
$config = Drupal::config('system.date');
$format = $config->get('formats.html_date') . ' ' . $config->get('formats.html_time');
$form['author']['date']['#description'] = t('Format: %format. Leave blank to use the time of form submission.', array('%format' => datetime_format_example($format)));
unset($form['author']['date']['#maxlength']);
}
/**
* Implements hook_node_prepare().
*/
function datetime_node_prepare(NodeInterface $node) {
// Prepare the 'Authored on' date to use datetime.
$node->date = new DrupalDateTime($node->created);
}
......@@ -42,7 +42,7 @@ protected function prepareEntity() {
$node->created = REQUEST_TIME;
}
else {
$node->date = new DrupalDateTime($node->created);
$node->date = format_date($node->created, 'custom', 'Y-m-d H:i:s O');
// Remove the log message from the original node entity.
$node->log = NULL;
}
......@@ -191,11 +191,11 @@ public function form(array $form, array &$form_state) {
'#weight' => -1,
'#description' => t('Leave blank for %anonymous.', array('%anonymous' => $user_config->get('anonymous'))),
);
$format = variable_get('date_format_html_date', 'Y-m-d') . ' ' . variable_get('date_format_html_time', 'H:i:s');
$form['author']['date'] = array(
'#type' => 'datetime',
'#type' => 'textfield',
'#title' => t('Authored on'),
'#description' => t('Format: %format. Leave blank to use the time of form submission.', array('%format' => datetime_format_example($format))),
'#maxlength' => 25,
'#description' => t('Format: %time. The date format is YYYY-MM-DD and %timezone is the time zone offset from UTC. Leave blank to use the time of form submission.', array('%time' => !empty($node->date) ? date_format(date_create($node->date), 'Y-m-d H:i:s O') : format_date($node->created, 'custom', 'Y-m-d H:i:s O'), '%timezone' => !empty($node->date) ? date_format(date_create($node->date), 'O') : format_date($node->created, 'custom', 'O'))),
'#default_value' => !empty($node->date) ? $node->date : '',
);
......@@ -337,7 +337,8 @@ public function validate(array $form, array &$form_state) {
// Validate the "authored on" field.
// The date element contains the date object.
if ($node->date instanceOf DrupalDateTime && $node->date->hasErrors()) {
$date = $node->date instanceof DrupalDateTime ? $node->date : new DrupalDateTime($node->date);
if ($date->hasErrors()) {
form_set_error('date', t('You have to specify a valid date.'));
}
......
......@@ -25,7 +25,7 @@ class NodeTranslationUITest extends EntityTranslationUITest {
*
* @var array
*/
public static $modules = array('language', 'translation_entity', 'node', 'field_ui');
public static $modules = array('language', 'translation_entity', 'node', 'datetime', 'field_ui');
public static function getInfo() {
return array(
......
......@@ -5,5 +5,3 @@ package: Core
version: VERSION
core: 8.x
configure: admin/structure/types
dependencies:
- datetime
......@@ -808,11 +808,9 @@ function node_update_8013() {
}
/**
* Enable Datetime module, which is now a required dependency.
* Empty update. See http://drupal.org/node/1836392.
*/
function node_update_8014() {
// Enable the datetime module.
module_enable(array('datetime'));
}
/**
......
......@@ -134,12 +134,12 @@ function testModuleEnableOrder() {
$this->assertModules(array('module_test'), TRUE);
\Drupal::state()->set('module_test.dependency', 'dependency');
// module_test creates a dependency chain:
// - forum depends on taxonomy, comment, history, and ban (via module_test)
// - forum depends on taxonomy, comment, datetime, history, and ban (via module_test)
// - taxonomy depends on options
// - options depends on number
// - ban depends on php (via module_test)
// The correct enable order is:
$expected_order = array('php', 'ban', 'comment', 'history', 'number', 'options', 'taxonomy', 'forum');
$expected_order = array('php', 'ban', 'datetime', 'comment', 'history', 'number', 'options', 'taxonomy', 'forum');
// Enable the modules through the UI, verifying that the dependency chain
// is correct.
......@@ -147,16 +147,17 @@ function testModuleEnableOrder() {
$edit['modules[Core][forum][enable]'] = 'forum';
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
$this->assertModules(array('forum'), FALSE);
$this->assertText(t('You must enable the History, Taxonomy, Options, Number, Comment, Ban, PHP Filter modules to install Forum.'));
$this->assertText(t('You must enable the History, Taxonomy, Options, Number, Comment, Datetime, Ban, PHP Filter modules to install Forum.'));
$edit['modules[Core][history][enable]'] = 'history';
$edit['modules[Core][options][enable]'] = 'options';
$edit['modules[Core][number][enable]'] = 'number';
$edit['modules[Core][taxonomy][enable]'] = 'taxonomy';
$edit['modules[Core][comment][enable]'] = 'comment';
$edit['modules[Core][datetime][enable]'] = 'datetime';
$edit['modules[Core][ban][enable]'] = 'ban';
$edit['modules[Core][php][enable]'] = 'php';
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
$this->assertModules(array('forum', 'ban', 'php', 'comment', 'history', 'taxonomy', 'options', 'number'), TRUE);
$this->assertModules(array('forum', 'ban', 'php', 'datetime', 'comment', 'history', 'taxonomy', 'options', 'number'), TRUE);
// Check the actual order which is saved by module_test_modules_enabled().
$module_order = \Drupal::state()->get('system_test.module_enable_order') ?: array();
......
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