.../Field/FieldFormatter/TimestampFormatter.php | 40 +++++++++ .../Field/Plugin/Field/FieldType/BooleanItem.php | 3 +- .../Field/Plugin/Field/FieldType/CreatedItem.php | 4 +- .../Field/Plugin/Field/FieldType/TimestampItem.php | 4 +- .../Plugin/Field/FieldWidget/BooleanWidget.php | 38 +++++++++ .../FieldWidget/RouteBasedAutocompleteWidget.php | 48 +++++++++++ .../Plugin/Field/FieldWidget/TimestampWidget.php | 86 +++++++++++++++++++ .../src/ContentTranslationHandler.php | 2 +- core/modules/datetime/datetime.module | 24 ++---- .../Field/FieldWidget/DateTimeTimestampWidget.php | 62 ++++++++++++++ .../modules/entity/src/Tests/EntityDisplayTest.php | 9 +- .../Field/FieldWidget/AutocompleteWidget.php | 2 +- .../src/Tests/EntityReferenceIntegrationTest.php | 23 +++-- core/modules/field/config/schema/field.schema.yml | 12 +++ .../config/install/rdf.mapping.node.forum.yml | 4 +- core/modules/forum/src/Tests/ForumBlockTest.php | 4 +- core/modules/node/node.info.yml | 1 + core/modules/node/node.module | 29 +++---- core/modules/node/src/Entity/Node.php | 71 +++++++++++++--- core/modules/node/src/NodeForm.php | 97 +++++----------------- core/modules/node/src/NodeTranslationHandler.php | 5 +- core/modules/node/src/NodeViewBuilder.php | 6 -- .../Tests/MultiStepNodeFormBasicOptionsTest.php | 8 +- core/modules/node/src/Tests/NodeCreationTest.php | 11 +-- .../node/src/Tests/NodeTranslationUITest.php | 10 +-- core/modules/node/src/Tests/PageEditTest.php | 12 +-- core/modules/node/src/Tests/PagePreviewTest.php | 6 +- .../node/templates/field--node--created.html.twig | 18 ++++ .../node/templates/field--node--uid.html.twig | 18 ++++ core/modules/node/templates/node.html.twig | 6 +- core/modules/rdf/rdf.module | 6 +- core/modules/rdf/src/CommonDataConverter.php | 14 ++++ .../rdf/src/Tests/CommentAttributesTest.php | 4 +- core/modules/rdf/src/Tests/CrudTest.php | 4 +- core/modules/rdf/src/Tests/NodeAttributesTest.php | 2 +- .../src/Tests/Entity/EntityTranslationFormTest.php | 25 +++--- core/modules/taxonomy/src/Tests/LegacyTest.php | 4 +- .../Plugin/Field/FieldWidget/TextareaWidget.php | 3 +- .../Field/FieldFormatter/AuthorFormatter.php | 50 +++++++++++ .../Field/FieldWidget/AuthorAutocompleteWidget.php | 74 +++++++++++++++++ .../install/rdf.mapping.comment.node__comment.yml | 4 +- .../config/install/rdf.mapping.node.article.yml | 4 +- .../config/install/rdf.mapping.node.page.yml | 4 +- core/themes/bartik/templates/node.html.twig | 8 +- 44 files changed, 662 insertions(+), 207 deletions(-) diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampFormatter.php new file mode 100644 index 0000000..6861a00 --- /dev/null +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampFormatter.php @@ -0,0 +1,40 @@ + $item) { + $elements[$delta] = array('#markup' => format_date($item->value)); + } + + return $elements; + } + +} diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php index 14d0f83..f2951ac 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php @@ -18,7 +18,8 @@ * id = "boolean", * label = @Translation("Boolean"), * description = @Translation("An entity field containing a boolean value."), - * no_ui = TRUE + * no_ui = TRUE, + * default_widget = "boolean", * ) */ class BooleanItem extends FieldItemBase { diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/CreatedItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/CreatedItem.php index 9b2e055..72c0ea9 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/CreatedItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/CreatedItem.php @@ -14,7 +14,9 @@ * id = "created", * label = @Translation("Created"), * description = @Translation("An entity field containing a UNIX timestamp of when the entity has been created."), - * no_ui = TRUE + * no_ui = TRUE, + * default_widget = "timestamp", + * default_formatter = "timestamp", * ) */ class CreatedItem extends TimestampItem { diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/TimestampItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/TimestampItem.php index ba432e3..72f71a2 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/TimestampItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/TimestampItem.php @@ -18,7 +18,9 @@ * id = "timestamp", * label = @Translation("Timestamp"), * description = @Translation("An entity field containing a UNIX timestamp value."), - * no_ui = TRUE + * no_ui = TRUE, + * default_widget = "timestamp", + * default_formatter = "timestamp", * ) */ class TimestampItem extends FieldItemBase { diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/BooleanWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/BooleanWidget.php new file mode 100644 index 0000000..66f4d07 --- /dev/null +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/BooleanWidget.php @@ -0,0 +1,38 @@ + 'checkbox', + '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL, + ); + + return $element; + } + +} diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/RouteBasedAutocompleteWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/RouteBasedAutocompleteWidget.php new file mode 100644 index 0000000..cf8b2c3 --- /dev/null +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/RouteBasedAutocompleteWidget.php @@ -0,0 +1,48 @@ + '', + ) + parent::defaultSettings(); + } + + /** + * {@inheritdoc} + */ + public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, array &$form_state) { + $element['target_id'] = $element + array( + '#type' => 'textfield', + '#default_value' => $items[$delta]->value, + '#autocomplete_route_name' => $this->getSetting('route_name'), + ); + + return $element; + } + +} diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/TimestampWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/TimestampWidget.php new file mode 100644 index 0000000..fc487de --- /dev/null +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/TimestampWidget.php @@ -0,0 +1,86 @@ + FALSE + ) + parent::defaultSettings(); + } + + /** + * {@inheritdoc} + */ + public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, array &$form_state) { + $default_value = isset($items[$delta]->value) ? format_date($items[$delta]->value, 'custom', 'Y-m-d H:i:s O') : ''; + $element['value'] = $element + array( + '#type' => 'textfield', + '#default_value' => $default_value, + '#maxlength' => 25, + '#element_validate' => array( + array($this, 'elementValidate'), + ), + ); + + if (!empty($default_value)) { + $example_time = date_format(date_create($default_value), 'Y-m-d H:i:s O'); + $timezone = date_format(date_create($default_value), 'O'); + } + else { + $example_time = format_date(REQUEST_TIME, 'custom', 'Y-m-d H:i:s O'); + $timezone = format_date(REQUEST_TIME, 'custom', 'O'); + } + $element['value']['#description'] = $this->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' => $example_time, '%timezone' => $timezone)); + + return $element; + } + + /** + * Validates an element. + * + * @todo Convert to massageFormValues() after https://drupal.org/node/2226723 lands. + */ + public function elementValidate($element, &$form_state, $form) { + $value = trim($element['#value']); + if (empty($value)) { + $value = $this->getSetting('use_request_time_on_empty') ? REQUEST_TIME : 0; + } + else { + $date = new DrupalDateTime($value); + if ($date->hasErrors()) { + $value = FALSE; + } + else { + $value = $date->getTimestamp(); + } + } + form_set_value($element, $value, $form_state); + } + +} diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index 7510d2e..f20bd2b 100644 --- a/core/modules/content_translation/src/ContentTranslationHandler.php +++ b/core/modules/content_translation/src/ContentTranslationHandler.php @@ -417,7 +417,7 @@ function entityFormValidate($form, &$form_state) { if (!empty($translation['name']) && !($account = user_load_by_name($translation['name']))) { form_set_error('content_translation][name', $form_state, t('The translation authoring username %name does not exist.', array('%name' => $translation['name']))); } - // Validate the "authored on" field. + // Validate the "created on" field. if (!empty($translation['created']) && strtotime($translation['created']) === FALSE) { form_set_error('content_translation][created', $form_state, t('You have to specify a valid translation authoring date.')); } diff --git a/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module index b5f98dd..058a027 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -999,21 +999,13 @@ function datetime_range_years($string, $date = NULL) { } /** - * Implements hook_form_BASE_FORM_ID_alter() for node forms. + * Implements hook_entity_base_field_info_alter(). */ -function datetime_form_node_form_alter(&$form, &$form_state, $form_id) { - // Alter the 'Authored on' date to use datetime. - $form['created']['#type'] = 'datetime'; - $date_format = entity_load('date_format', 'html_date')->getPattern(); - $time_format = entity_load('date_format', 'html_time')->getPattern(); - $form['created']['#description'] = t('Format: %format. Leave blank to use the time of form submission.', array('%format' => datetime_format_example($date_format . ' ' . $time_format))); - unset($form['created']['#maxlength']); -} - -/** - * Implements hook_node_prepare_form(). - */ -function datetime_node_prepare_form(NodeInterface $node, $operation, array &$form_state) { - // Prepare the 'Authored on' date to use datetime. - $node->date = DrupalDateTime::createFromTimestamp($node->getCreatedTime()); +function datetime_entity_base_field_info_alter(&$fields, \Drupal\Core\Entity\EntityTypeInterface $entity_type) { + if ($entity_type->id() == 'node') { + $fields['created']->setDisplayOptions('form', array( + 'type' => 'datetime_timestamp', + 'weight' => 0, + )); + } } diff --git a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeTimestampWidget.php b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeTimestampWidget.php new file mode 100644 index 0000000..6c50058 --- /dev/null +++ b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeTimestampWidget.php @@ -0,0 +1,62 @@ +getPattern(); + $time_format = entity_load('date_format', 'html_time')->getPattern(); + $default_value = isset($items[$delta]->value) ? DrupalDateTime::createFromTimestamp($items[$delta]->value) : ''; + $element['value'] = $element + array( + '#type' => 'datetime', + '#default_value' => $default_value, + '#element_validate' => array( + array($this, 'elementValidate'), + ), + ); + $element['value']['#description'] = $this->t('Format: %format. Leave blank to use the time of form submission.', array('%format' => datetime_format_example($date_format . ' ' . $time_format))); + + return $element; + } + + /** + * Validates an element. + * + * @todo Convert to massageFormValues() after https://drupal.org/node/2226723 lands. + */ + public function elementValidate($element, &$form_state, $form) { + $date = $element['#value']['object']; + if ($date->hasErrors()) { + $value = -1; + } + else { + $value = $date->getTimestamp(); + } + form_set_value($element, $value, $form_state); + } + +} diff --git a/core/modules/entity/src/Tests/EntityDisplayTest.php b/core/modules/entity/src/Tests/EntityDisplayTest.php index d76d603..bc518ba 100644 --- a/core/modules/entity/src/Tests/EntityDisplayTest.php +++ b/core/modules/entity/src/Tests/EntityDisplayTest.php @@ -288,19 +288,22 @@ public function testRenameDeleteBundle() { $this->assertEqual('article_rename', $new_form_display->bundle); $this->assertEqual('node.article_rename.default', $new_form_display->id); - $expected_dependencies = array( + $expected_view_dependencies = array( + 'entity' => array('field.instance.node.article_rename.body', 'node.type.article_rename'), + 'module' => array('text', 'user') + );$expected_form_dependencies = array( 'entity' => array('field.instance.node.article_rename.body', 'node.type.article_rename'), 'module' => array('text') ); // Check that the display has dependencies on the bundle, fields and the // modules that provide the formatters. $dependencies = $new_display->calculateDependencies(); - $this->assertEqual($expected_dependencies, $dependencies); + $this->assertEqual($expected_view_dependencies, $dependencies); // Check that the form display has dependencies on the bundle, fields and // the modules that provide the formatters. $dependencies = $new_form_display->calculateDependencies(); - $this->assertEqual($expected_dependencies, $dependencies); + $this->assertEqual($expected_form_dependencies, $dependencies); // Delete the bundle. $type->delete(); diff --git a/core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteWidget.php b/core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteWidget.php index 234eb7a..f535a95 100644 --- a/core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteWidget.php +++ b/core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteWidget.php @@ -72,7 +72,7 @@ public function elementValidate($element, &$form_state, $form) { elseif (preg_match("/.+\(([\w.]+)\)/", $element['#value'], $matches)) { $value = $matches[1]; } - if (!$value) { + if ($value === NULL) { // Try to get a match from the input string when the user didn't use the // autocomplete but filled in a value manually. $handler = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($this->fieldDefinition); diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php index cfe4042..9654e3e 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php @@ -59,6 +59,7 @@ public function setUp() { * Tests the entity reference field with all its supported field widgets. */ public function testSupportedEntityTypesAndWidgets() { + $user_id = mt_rand(128, 256); foreach ($this->getTestEntities() as $referenced_entities) { $this->fieldName = 'field_test_' . $referenced_entities[0]->getEntityTypeId(); @@ -69,9 +70,14 @@ public function testSupportedEntityTypesAndWidgets() { entity_get_form_display($this->entityType, $this->bundle, 'default')->setComponent($this->fieldName)->save(); $entity_name = $this->randomName(); + $user_id++; + entity_create('user', array( + 'uid' => $user_id, + 'name' => $this->randomName(), + ))->save(); $edit = array( 'name' => $entity_name, - 'user_id' => mt_rand(0, 128), + 'user_id' => $user_id, $this->fieldName . '[0][target_id]' => $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')', // Test an input of the entity label without a ' (entity_id)' suffix. $this->fieldName . '[1][target_id]' => $referenced_entities[1]->label(), @@ -94,9 +100,14 @@ public function testSupportedEntityTypesAndWidgets() { $target_id = $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')'; // Test an input of the entity label without a ' (entity_id)' suffix. $target_id .= ', ' . $referenced_entities[1]->label(); + $user_id++; + entity_create('user', array( + 'uid' => $user_id, + 'name' => $this->randomName(), + ))->save(); $edit = array( 'name' => $entity_name, - 'user_id' => mt_rand(0, 128), + 'user_id' => $user_id, $this->fieldName . '[target_id]' => $target_id, ); $this->drupalPostForm($this->entityType . '/add', $edit, t('Save')); @@ -111,9 +122,11 @@ public function testSupportedEntityTypesAndWidgets() { // Test all the other widgets supported by the entity reference field. // Since we don't know the form structure for these widgets, just test // that editing and saving an already created entity works. + // Also exclude the special author reference widgets. + $exclude = array('entity_reference_autocomplete', 'entity_reference_autocomplete_tags', 'route_based_autocomplete', 'author_autocomplete'); $entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name))); $supported_widgets = \Drupal::service('plugin.manager.field.widget')->getOptions('entity_reference'); - $supported_widget_types = array_diff(array_keys($supported_widgets), array('entity_reference_autocomplete', 'entity_reference_autocomplete_tags')); + $supported_widget_types = array_diff(array_keys($supported_widgets), $exclude); foreach ($supported_widget_types as $widget_type) { entity_get_form_display($this->entityType, $this->bundle, 'default')->setComponent($this->fieldName, array( @@ -160,9 +173,9 @@ protected function getTestEntities() { $config_entity_2 = entity_create('config_test', array('id' => $this->randomName(), 'label' => $this->randomName())); $config_entity_2->save(); - $content_entity_1 = entity_create('entity_test', array('name' => $this->randomName())); + $content_entity_1 = entity_create('entity_test', array('name' => $this->randomName(), 'user_id' => 0)); $content_entity_1->save(); - $content_entity_2 = entity_create('entity_test', array('name' => $this->randomName())); + $content_entity_2 = entity_create('entity_test', array('name' => $this->randomName(), 'user_id' => 0)); $content_entity_2->save(); return array( diff --git a/core/modules/field/config/schema/field.schema.yml b/core/modules/field/config/schema/field.schema.yml index 7018b5f..ca57b6a 100644 --- a/core/modules/field/config/schema/field.schema.yml +++ b/core/modules/field/config/schema/field.schema.yml @@ -291,3 +291,15 @@ entity_form_display.field.number: placeholder: type: label label: 'Placeholder' + +entity_form_display.field.timestamp: + type: entity_field_form_display_base + label: 'Timestamp default display format settings' + mapping: + settings: + type: mapping + label: 'Settings' + mapping: + use_request_time_on_empty: + type: boolean + label: 'Whether the current request time should be used if an empty value is submitted' diff --git a/core/modules/forum/config/install/rdf.mapping.node.forum.yml b/core/modules/forum/config/install/rdf.mapping.node.forum.yml index 7db68c7..be874cd 100644 --- a/core/modules/forum/config/install/rdf.mapping.node.forum.yml +++ b/core/modules/forum/config/install/rdf.mapping.node.forum.yml @@ -11,12 +11,12 @@ fieldMappings: properties: - 'schema:dateCreated' datatype_callback: - callable: 'date_iso8601' + callable: 'Drupal\rdf\CommonDataConverter::dateIso8601Value' changed: properties: - 'schema:dateModified' datatype_callback: - callable: 'date_iso8601' + callable: 'Drupal\rdf\CommonDataConverter::dateIso8601Value' body: properties: - 'schema:text' diff --git a/core/modules/forum/src/Tests/ForumBlockTest.php b/core/modules/forum/src/Tests/ForumBlockTest.php index 30d14d9..73b34c1 100644 --- a/core/modules/forum/src/Tests/ForumBlockTest.php +++ b/core/modules/forum/src/Tests/ForumBlockTest.php @@ -169,8 +169,8 @@ protected function createForumTopics($count = 5) { 'body[0][value]' => $body, // Forum posts are ordered by timestamp, so force a unique timestamp by // adding the index. - 'created[date]' => $date->format('Y-m-d'), - 'created[time]' => $date->format('H:i:s'), + 'created[0][value][date]' => $date->format('Y-m-d'), + 'created[0][value][time]' => $date->format('H:i:s'), ); // Create the forum topic, preselecting the forum ID via a URL parameter. diff --git a/core/modules/node/node.info.yml b/core/modules/node/node.info.yml index e61b363..ab8e3c3 100644 --- a/core/modules/node/node.info.yml +++ b/core/modules/node/node.info.yml @@ -7,3 +7,4 @@ core: 8.x configure: node.overview_types dependencies: - text + - entity_reference diff --git a/core/modules/node/node.module b/core/modules/node/node.module index f23559e..1d7d89c 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -181,6 +181,14 @@ function node_theme() { 'base hook' => 'field', 'template' => 'field--node--title', ), + 'field__node__uid' => array( + 'base hook' => 'field', + 'template' => 'field--node--uid', + ), + 'field__node__created' => array( + 'base hook' => 'field', + 'template' => 'field--node--created', + ), ); } @@ -202,15 +210,6 @@ function node_entity_view_display_alter(EntityViewDisplayInterface $display, $co } /** - * Implements hook_entity_form_display_alter(). - */ -function node_entity_form_display_alter(EntityFormDisplayInterface $form_display, $context) { - if ($context['entity_type'] == 'node') { - $node_type = node_type_load($context['bundle']); - } -} - -/** * Gathers a listing of links to nodes. * * @param $result @@ -612,14 +611,10 @@ function template_preprocess_node(&$variables) { $variables['node'] = $variables['elements']['#node']; /** @var \Drupal\node\NodeInterface $node */ $node = $variables['node']; - - $variables['date'] = format_date($node->getCreatedTime()); - $username = array( - '#theme' => 'username', - '#account' => $node->getOwner(), - '#link_options' => array('attributes' => array('rel' => 'author')), - ); - $variables['author_name'] = drupal_render($username); + $variables['date'] = drupal_render($variables['elements']['created'], TRUE); + unset($variables['elements']['created']); + $variables['author_name'] = drupal_render($variables['elements']['uid'], TRUE); + unset($variables['elements']['uid']); $variables['url'] = $node->url('canonical', array( 'language' => $node->language(), diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php index 19f311e..df8f260 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -371,10 +371,29 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['uid'] = FieldDefinition::create('entity_reference') ->setLabel(t('Author')) - ->setDescription(t('The user that is the node author.')) + ->setDescription(t('The user ID of the node author.')) ->setRevisionable(TRUE) - ->setSetting('target_type', 'user') - ->setTranslatable(TRUE); + ->setSettings(array( + 'target_type' => 'user', + 'default_value' => 0, + 'handler' => 'default', + )) + ->setTranslatable(TRUE) + ->setDisplayOptions('view', array( + 'label' => 'hidden', + 'type' => 'author', + 'weight' => 0, + )) + ->setDisplayOptions('form', array( + 'type' => 'entity_reference_autocomplete', + 'weight' => -1, + 'settings' => array( + 'match_operator' => 'CONTAINS', + 'size' => '60', + 'autocomplete_type' => 'tags', + 'placeholder' => '', + ), + )); $fields['status'] = FieldDefinition::create('boolean') ->setLabel(t('Publishing status')) @@ -383,10 +402,23 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setTranslatable(TRUE); $fields['created'] = FieldDefinition::create('created') - ->setLabel(t('Created')) + ->setLabel(t('Publication date')) ->setDescription(t('The time that the node was created.')) ->setRevisionable(TRUE) - ->setTranslatable(TRUE); + ->setTranslatable(TRUE) + ->setDisplayOptions('view', array( + 'label' => 'hidden', + 'type' => 'timestamp', + 'weight' => 0, + )) + ->setDisplayOptions('form', array( + 'type' => 'timestamp', + 'weight' => 0, + 'settings' => array( + 'use_request_time_on_empty' => TRUE, + ), + )) + ->setDisplayConfigurable('form', TRUE); $fields['changed'] = FieldDefinition::create('changed') ->setLabel(t('Changed')) @@ -395,16 +427,22 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setTranslatable(TRUE); $fields['promote'] = FieldDefinition::create('boolean') - ->setLabel(t('Promote')) - ->setDescription(t('A boolean indicating whether the node should be displayed on the front page.')) + ->setLabel(t('Promoted to front page')) ->setRevisionable(TRUE) - ->setTranslatable(TRUE); + ->setTranslatable(TRUE) + ->setDisplayOptions('form', array( + 'type' => 'boolean', + 'weight' => -1, + )); $fields['sticky'] = FieldDefinition::create('boolean') - ->setLabel(t('Sticky')) - ->setDescription(t('A boolean indicating whether the node should be displayed at the top of lists in which it appears.')) + ->setLabel(t('Sticky at top of lists')) ->setRevisionable(TRUE) - ->setTranslatable(TRUE); + ->setTranslatable(TRUE) + ->setDisplayOptions('form', array( + 'type' => 'boolean', + 'weight' => 0, + )); $fields['revision_timestamp'] = FieldDefinition::create('created') ->setLabel(t('Revision timestamp')) @@ -421,9 +459,16 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['revision_log'] = FieldDefinition::create('string_long') ->setLabel(t('Revision log message')) - ->setDescription(t('The log entry explaining the changes in this revision.')) + ->setDescription(t('Briefly describe the changes you have made.')) ->setRevisionable(TRUE) - ->setTranslatable(TRUE); + ->setTranslatable(TRUE) + ->setDisplayOptions('form', array( + 'type' => 'text_textarea', + 'weight' => 0, + 'settings' => array( + 'rows' => 4, + ), + )); return $fields; } diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php index 69d91a5..8c80699 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -7,11 +7,8 @@ namespace Drupal\node; -use Drupal\Component\Utility\NestedArray; -use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Language\LanguageInterface; -use Drupal\Component\Utility\String; /** * Form controller for the node edit forms. @@ -36,8 +33,7 @@ protected function prepareEntity() { $this->settings = $type->getModuleSettings('node'); if (!$node->isNew()) { - $node->date = format_date($node->getCreatedTime(), 'custom', 'Y-m-d H:i:s O'); - // Remove the revision log message from the original node entity. + // Remove the log message from the original node entity. $node->revision_log = NULL; } } @@ -49,6 +45,16 @@ public function form(array $form, array &$form_state) { /** @var \Drupal\node\NodeInterface $node */ $node = $this->entity; + // Create the "advanced" vertical tabs before building the form, so that + // field widgets may detect its presence and choose to live there. + $form['advanced'] = array( + '#type' => 'vertical_tabs', + '#attributes' => array('class' => array('entity-meta')), + '#weight' => 99, + ); + + $form = parent::form($form, $form_state, $node); + if ($this->operation == 'edit') { $form['#title'] = $this->t('Edit @type @title', array('@type' => node_get_type_label($node), '@title' => $node->label())); } @@ -85,14 +91,8 @@ public function form(array $form, array &$form_state) { '#access' => isset($language_configuration['language_show']) && $language_configuration['language_show'], ); - $form['advanced'] = array( - '#type' => 'vertical_tabs', - '#attributes' => array('class' => array('entity-meta')), - '#weight' => 99, - ); - - // Add a revision log field if the "Create new revision" option is checked, - // or if the current user has the ability to check that option. + // Add a revision_log field if the "Create new revision" option is checked, or if + // the current user has the ability to check that option. $form['revision_information'] = array( '#type' => 'details', '#group' => 'advanced', @@ -115,14 +115,12 @@ public function form(array $form, array &$form_state) { '#default_value' => !empty($this->settings['options']['revision']), '#access' => $node->isNewRevision() || $current_user->hasPermission('administer nodes'), '#group' => 'revision_information', + // Ensure the 'Create new revision' checkbox sits above the revision log + // message. + '#weight' => -1, ); $form['revision_log'] = array( - '#type' => 'textarea', - '#title' => t('Revision log message'), - '#rows' => 4, - '#default_value' => !empty($node->revision_log->value) ? $node->revision_log->value : '', - '#description' => t('Briefly describe the changes you have made.'), '#states' => array( 'visible' => array( ':input[name="revision"]' => array('checked' => TRUE), @@ -154,25 +152,16 @@ public function form(array $form, array &$form_state) { ); $form['uid'] = array( - '#type' => 'textfield', - '#title' => t('Authored by'), - '#maxlength' => 60, - '#autocomplete_route_name' => 'user.autocomplete', - '#default_value' => $node->getOwnerId()? $node->getOwner()->getUsername() : '', - '#weight' => -1, - '#description' => t('Leave blank for %anonymous.', array('%anonymous' => $user_config->get('anonymous'))), '#group' => 'author', '#access' => $current_user->hasPermission('administer nodes'), ); + $form['uid']['widget'][0]['value']['#title'] = $this->t('Authored by'); + $form['created'] = array( - '#type' => 'textfield', - '#title' => t('Authored on'), - '#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->getCreatedTime(), 'custom', 'Y-m-d H:i:s O'), '%timezone' => !empty($node->date) ? date_format(date_create($node->date), 'O') : format_date($node->getCreatedTime(), 'custom', 'O'))), - '#default_value' => !empty($node->date) ? $node->date : '', '#group' => 'author', '#access' => $current_user->hasPermission('administer nodes'), ); + $form['created']['widget'][0]['value']['#title'] = $this->t('Authored on'); // Node options for administrators. $form['options'] = array( @@ -190,22 +179,16 @@ public function form(array $form, array &$form_state) { ); $form['promote'] = array( - '#type' => 'checkbox', - '#title' => t('Promoted to front page'), - '#default_value' => $node->isPromoted(), '#group' => 'options', '#access' => $current_user->hasPermission('administer nodes'), ); $form['sticky'] = array( - '#type' => 'checkbox', - '#title' => t('Sticky at top of lists'), - '#default_value' => $node->isSticky(), '#group' => 'options', '#access' => $current_user->hasPermission('administer nodes'), ); - return parent::form($form, $form_state, $node); + return $form; } /** @@ -299,21 +282,6 @@ public function validate(array $form, array &$form_state) { $this->setFormError('changed', $form_state, $this->t('The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved.')); } - // Validate the "authored by" field. - if (!empty($form_state['values']['uid']) && !user_load_by_name($form_state['values']['uid'])) { - // The use of empty() is mandatory in the context of usernames - // as the empty string denotes the anonymous user. In case we - // are dealing with an anonymous user we set the user ID to 0. - $this->setFormError('uid', $form_state, $this->t('The username %name does not exist.', array('%name' => $form_state['values']['uid']))); - } - - // Validate the "authored on" field. - // The date element contains the date object. - $date = $node->date instanceof DrupalDateTime ? $node->date : new DrupalDateTime($node->date); - if ($date->hasErrors()) { - $this->setFormError('date', $form_state, $this->t('You have to specify a valid date.')); - } - // Invoke hook_node_validate() for validation needed by modules. // Can't use \Drupal::moduleHandler()->invokeAll(), because $form_state must // be receivable by reference. @@ -403,31 +371,6 @@ public function unpublish(array $form, array &$form_state) { } /** - * {@inheritdoc} - */ - public function buildEntity(array $form, array &$form_state) { - /** @var \Drupal\node\NodeInterface $entity */ - $entity = parent::buildEntity($form, $form_state); - // A user might assign the node author by entering a user name in the node - // form, which we then need to translate to a user ID. - if (!empty($form_state['values']['uid']) && $account = user_load_by_name($form_state['values']['uid'])) { - $entity->setOwnerId($account->id()); - } - else { - $entity->setOwnerId(0); - } - - if (!empty($form_state['values']['created']) && $form_state['values']['created'] instanceOf DrupalDateTime) { - $entity->setCreatedTime($form_state['values']['created']->getTimestamp()); - } - else { - $entity->setCreatedTime(REQUEST_TIME); - } - return $entity; - } - - - /** * Overrides Drupal\Core\Entity\EntityForm::save(). */ public function save(array $form, array &$form_state) { diff --git a/core/modules/node/src/NodeTranslationHandler.php b/core/modules/node/src/NodeTranslationHandler.php index 21ab7e0..aea2d3b 100644 --- a/core/modules/node/src/NodeTranslationHandler.php +++ b/core/modules/node/src/NodeTranslationHandler.php @@ -80,8 +80,9 @@ public function entityFormEntityBuild($entity_type, EntityInterface $entity, arr $translation['status'] = $form_controller->getEntity()->isPublished(); // $form['content_translation']['name'] is the equivalent field // for translation author uid. - $translation['name'] = $form_state['values']['uid']; - $translation['created'] = $form_state['values']['created']; + $account = user_load($form_state['values']['uid'][0]['target_id']); + $translation['name'] = $account ? $account->getUsername() : ''; + $translation['created'] = format_date($form_state['values']['created'][0]['value'], 'custom', 'Y-m-d H:i:s O'); } parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state); } diff --git a/core/modules/node/src/NodeViewBuilder.php b/core/modules/node/src/NodeViewBuilder.php index 606ef36..5521812 100644 --- a/core/modules/node/src/NodeViewBuilder.php +++ b/core/modules/node/src/NodeViewBuilder.php @@ -75,12 +75,6 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langco if (isset($defaults['#cache']) && isset($entity->in_preview)) { unset($defaults['#cache']); } - else { - // The node 'submitted' info is not rendered in a standard way (renderable - // array) so we have to add a cache tag manually. - // @todo Delete this once https://drupal.org/node/2226493 lands. - $defaults['#cache']['tags']['user'][] = $entity->getOwnerId(); - } return $defaults; } diff --git a/core/modules/node/src/Tests/MultiStepNodeFormBasicOptionsTest.php b/core/modules/node/src/Tests/MultiStepNodeFormBasicOptionsTest.php index 3baab91..17d6f1e 100644 --- a/core/modules/node/src/Tests/MultiStepNodeFormBasicOptionsTest.php +++ b/core/modules/node/src/Tests/MultiStepNodeFormBasicOptionsTest.php @@ -56,13 +56,13 @@ function testMultiStepNodeFormBasicOptions() { $edit = array( 'title[0][value]' => 'a', - 'promote' => FALSE, - 'sticky' => 1, + 'promote[0][value]' => FALSE, + 'sticky[0][value]' => 1, "{$this->field_name}[0][value]" => $this->randomString(32), ); $this->drupalPostForm('node/add/page', $edit, t('Add another item')); - $this->assertNoFieldChecked('edit-promote', 'promote stayed unchecked'); - $this->assertFieldChecked('edit-sticky', 'sticky stayed checked'); + $this->assertNoFieldChecked('edit-promote-0-value', 'promote stayed unchecked'); + $this->assertFieldChecked('edit-sticky-0-value', 'sticky stayed checked'); } } diff --git a/core/modules/node/src/Tests/NodeCreationTest.php b/core/modules/node/src/Tests/NodeCreationTest.php index a305ca5..beb0145 100644 --- a/core/modules/node/src/Tests/NodeCreationTest.php +++ b/core/modules/node/src/Tests/NodeCreationTest.php @@ -57,9 +57,9 @@ function testNodeCreation() { $this->assertTrue($node, 'Node found in database.'); // Verify that pages do not show submitted information by default. - $submitted_by = t('Submitted by !username on !datetime', array('!username' => $this->loggedInUser->getUsername(), '!datetime' => format_date($node->getCreatedTime()))); $this->drupalGet('node/' . $node->id()); - $this->assertNoText($submitted_by); + $this->assertNoText($node->getOwner()->getUsername()); + $this->assertNoText(format_date($node->getCreatedTime())); // Change the node type setting to show submitted by information. $node_type = entity_load('node_type', 'page'); @@ -67,7 +67,8 @@ function testNodeCreation() { $node_type->save(); $this->drupalGet('node/' . $node->id()); - $this->assertText($submitted_by); + $this->assertText($node->getOwner()->getUsername()); + $this->assertText(format_date($node->getCreatedTime())); } /** @@ -146,7 +147,7 @@ public function testAuthorAutocomplete() { $this->drupalGet('node/add/page'); - $result = $this->xpath('//input[@id="edit-uid" and contains(@data-autocomplete-path, "user/autocomplete")]'); + $result = $this->xpath('//input[@id="edit-uid-0-value" and contains(@data-autocomplete-path, "user/autocomplete")]'); $this->assertEqual(count($result), 0, 'No autocompletion without access user profiles.'); $admin_user = $this->drupalCreateUser(array('administer nodes', 'create page content', 'access user profiles')); @@ -154,7 +155,7 @@ public function testAuthorAutocomplete() { $this->drupalGet('node/add/page'); - $result = $this->xpath('//input[@id="edit-uid" and contains(@data-autocomplete-path, "user/autocomplete")]'); + $result = $this->xpath('//input[@id="edit-uid-0-target-id" and contains(@data-autocomplete-path, "/entity_reference/autocomplete/tags/uid/node/page")]'); $this->assertEqual(count($result), 1, 'Ensure that the user does have access to the autocompletion'); } diff --git a/core/modules/node/src/Tests/NodeTranslationUITest.php b/core/modules/node/src/Tests/NodeTranslationUITest.php index b6dde03..f833b31 100644 --- a/core/modules/node/src/Tests/NodeTranslationUITest.php +++ b/core/modules/node/src/Tests/NodeTranslationUITest.php @@ -152,11 +152,11 @@ protected function doTestAuthoringInfo() { 'promote' => (bool) mt_rand(0, 1), ); $edit = array( - 'uid' => $user->getUsername(), - 'created[date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'), - 'created[time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'), - 'sticky' => $values[$langcode]['sticky'], - 'promote' => $values[$langcode]['promote'], + 'uid[0][target_id]' => $user->getUsername(), + 'created[0][value][date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'), + 'created[0][value][time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'), + 'sticky[0][value]' => $values[$langcode]['sticky'], + 'promote[0][value]' => $values[$langcode]['promote'], ); $this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity, $langcode), array('language' => $languages[$langcode])); } diff --git a/core/modules/node/src/Tests/PageEditTest.php b/core/modules/node/src/Tests/PageEditTest.php index 9ab628e..b471f63 100644 --- a/core/modules/node/src/Tests/PageEditTest.php +++ b/core/modules/node/src/Tests/PageEditTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\Component\Utility\String; + /** * Create a node and test node edit functionality. * @@ -108,21 +110,21 @@ function testPageAuthoredBy() { // Try to change the 'authored by' field to an invalid user name. $edit = array( - 'uid' => 'invalid-name', + 'uid[0][target_id]' => 'invalid-name', ); $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); - $this->assertText('The username invalid-name does not exist.'); + $this->assertRaw(t('There are no entities matching "%name".', array('%name' => 'invalid-name'))); // Change the authored by field to an empty string, which should assign // authorship to the anonymous user (uid 0). - $edit['uid'] = ''; + $edit['uid[0][target_id]'] = 'Anonymous (0)'; $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); $node = node_load($node->id(), TRUE); $this->assertIdentical($node->getOwnerId(), '0', 'Node authored by anonymous user.'); // Change the authored by field to another user's name (that is not // logged in). - $edit['uid'] = $this->web_user->getUsername(); + $edit['uid[0][target_id]'] = $this->web_user->getUsername(); $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); $node = node_load($node->id(), TRUE); $this->assertIdentical($node->getOwnerId(), $this->web_user->id(), 'Node authored by normal user.'); @@ -130,6 +132,6 @@ function testPageAuthoredBy() { // Check that normal users cannot change the authored by information. $this->drupalLogin($this->web_user); $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertNoFieldByName('uid'); + $this->assertNoFieldByName('uid[0][target_id]'); } } diff --git a/core/modules/node/src/Tests/PagePreviewTest.php b/core/modules/node/src/Tests/PagePreviewTest.php index b40ea57..68b8703 100644 --- a/core/modules/node/src/Tests/PagePreviewTest.php +++ b/core/modules/node/src/Tests/PagePreviewTest.php @@ -186,7 +186,7 @@ function testPagePreviewWithRevisions() { $edit[$title_key] = $this->randomName(8); $edit[$body_key] = $this->randomName(16); $edit[$term_key] = $this->term->id(); - $edit['revision_log'] = $this->randomName(32); + $edit['revision_log[0][value]'] = $this->randomName(32); $this->drupalPostForm('node/add/page', $edit, t('Preview')); // Check that the preview is displaying the title, body and term. @@ -200,8 +200,8 @@ function testPagePreviewWithRevisions() { $this->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.'); $this->assertFieldByName($term_key, $edit[$term_key], 'Term field displayed.'); - // Check that the revision log field has the correct value. - $this->assertFieldByName('revision_log', $edit['revision_log'], 'Revision log field displayed.'); + // Check that the log field has the correct value. + $this->assertFieldByName('revision_log[0][value]', $edit['revision_log[0][value]'], 'Revision Log field displayed.'); } } diff --git a/core/modules/node/templates/field--node--created.html.twig b/core/modules/node/templates/field--node--created.html.twig new file mode 100644 index 0000000..6c8a687 --- /dev/null +++ b/core/modules/node/templates/field--node--created.html.twig @@ -0,0 +1,18 @@ +{# +/** +* @file +* Default theme implementation for the node created field. +* +* This is an override of field.html.twig for the node created field. See that +* template for documentation about its details and overrides. +* +* Available variables: +* - attributes: HTML attributes for the containing span element. +* - items: List of all the field items. +* +* @see field.html.twig +* +* @ingroup themeable +*/ +#} +{{ items }} diff --git a/core/modules/node/templates/field--node--uid.html.twig b/core/modules/node/templates/field--node--uid.html.twig new file mode 100644 index 0000000..1fb0a6d --- /dev/null +++ b/core/modules/node/templates/field--node--uid.html.twig @@ -0,0 +1,18 @@ +{# +/** +* @file +* Default theme implementation for the node user field. +* +* This is an override of field.html.twig for the node user field. See that +* template for documentation about its details and overrides. +* +* Available variables: +* - attributes: HTML attributes for the containing span element. +* - items: List of all the field items. +* +* @see field.html.twig +* +* @ingroup themeable +*/ +#} +{{ items }} diff --git a/core/modules/node/templates/node.html.twig b/core/modules/node/templates/node.html.twig index c80eecb..a0e629e 100644 --- a/core/modules/node/templates/node.html.twig +++ b/core/modules/node/templates/node.html.twig @@ -23,10 +23,8 @@ * - author_picture: The node author user entity, rendered using the "compact" * view mode. * - metadata: Metadata for this node. - * - date: Formatted creation date. Preprocess functions can reformat it by - * calling format_date() with the desired parameters on - * $variables['created']. - * - author_name: Themed username of node author output from theme_username(). + * - date: Themed creation date field. + * - author_name: Themed author name field. * - url: Direct URL of the current node. * - display_submitted: Whether submission information should be displayed. * - attributes: HTML attributes for the containing element. diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index 1221147..ad7bb67 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -216,7 +216,7 @@ function rdf_entity_prepare_view($entity_type, array $entities, array $displays) $field_mapping = $mapping->getPreparedFieldMapping($name); if ($field_mapping) { foreach ($entity->get($name) as $item) { - $item->_attributes += rdf_rdfa_attributes($field_mapping, $item->getValue()); + $item->_attributes += rdf_rdfa_attributes($field_mapping, $item->toArray()); } } } @@ -233,7 +233,7 @@ function rdf_comment_load($comments) { // to optimize performance for websites that implement an entity cache. $created_mapping = rdf_get_mapping('comment', $comment->bundle()) ->getPreparedFieldMapping('created'); - $comment->rdf_data['date'] = rdf_rdfa_attributes($created_mapping, $comment->getCreatedTime()); + $comment->rdf_data['date'] = rdf_rdfa_attributes($created_mapping, $comment->get('created')->first()->toArray()); $entity = $comment->getCommentedEntity(); $comment->rdf_data['entity_uri'] = $entity->url(); if ($comment->hasParentComment()) { @@ -304,7 +304,7 @@ function rdf_preprocess_node(&$variables) { // Adds RDFa markup for the date. $created_mapping = $mapping->getPreparedFieldMapping('created'); if (!empty($created_mapping) && $variables['display_submitted']) { - $date_attributes = rdf_rdfa_attributes($created_mapping, $variables['node']->getCreatedTime()); + $date_attributes = rdf_rdfa_attributes($created_mapping, $variables['node']->get('created')[0]->getValue()); $rdf_metadata = array( '#theme' => 'rdf_metadata', '#metadata' => array($date_attributes), diff --git a/core/modules/rdf/src/CommonDataConverter.php b/core/modules/rdf/src/CommonDataConverter.php index e27f48b..c91f947 100644 --- a/core/modules/rdf/src/CommonDataConverter.php +++ b/core/modules/rdf/src/CommonDataConverter.php @@ -23,4 +23,18 @@ class CommonDataConverter { static function rawValue($data) { return $data; } + + /** + * Converts a date entity field array into an ISO 8601 timestamp string. + * + * @param array $data + * The array containing the 'value' element. + * + * @return string + * Returns the ISO 8601 timestamp. + */ + static function dateIso8601Value($data) { + return date_iso8601($data['value']); + } + } diff --git a/core/modules/rdf/src/Tests/CommentAttributesTest.php b/core/modules/rdf/src/Tests/CommentAttributesTest.php index e8b15d7..a9a4326 100644 --- a/core/modules/rdf/src/Tests/CommentAttributesTest.php +++ b/core/modules/rdf/src/Tests/CommentAttributesTest.php @@ -72,12 +72,12 @@ public function setUp() { 'created' => array( 'properties' => array('dc:date', 'dc:created'), 'datatype' => 'xsd:dateTime', - 'datatype_callback' => array('callable' => 'date_iso8601'), + 'datatype_callback' => array('callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'), ), 'changed' => array( 'properties' => array('dc:modified'), 'datatype' => 'xsd:dateTime', - 'datatype_callback' => array('callable' => 'date_iso8601'), + 'datatype_callback' => array('callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'), ), 'comment_body' => array( 'properties' => array('content:encoded'), diff --git a/core/modules/rdf/src/Tests/CrudTest.php b/core/modules/rdf/src/Tests/CrudTest.php index 772ec4f..0696844 100644 --- a/core/modules/rdf/src/Tests/CrudTest.php +++ b/core/modules/rdf/src/Tests/CrudTest.php @@ -75,7 +75,7 @@ function testFieldMapping() { $mapping = array( 'properties' => array('dc:created'), 'datatype' => 'xsd:dateTime', - 'datatype_callback' => array('callable' => 'date_iso8601'), + 'datatype_callback' => array('callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'), ); rdf_get_mapping($this->entity_type, $this->bundle) ->setFieldMapping($field_name, $mapping) @@ -88,7 +88,7 @@ function testFieldMapping() { $mapping = array( 'properties' => array('dc:date'), 'datatype' => 'foo:bar', - 'datatype_callback' => array('callable' => 'date_iso8601'), + 'datatype_callback' => array('callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'), ); rdf_get_mapping($this->entity_type, $this->bundle) ->setFieldMapping($field_name, $mapping) diff --git a/core/modules/rdf/src/Tests/NodeAttributesTest.php b/core/modules/rdf/src/Tests/NodeAttributesTest.php index 8b2badf..f84faf2 100644 --- a/core/modules/rdf/src/Tests/NodeAttributesTest.php +++ b/core/modules/rdf/src/Tests/NodeAttributesTest.php @@ -36,7 +36,7 @@ public function setUp() { ->setFieldMapping('created', array( 'properties' => array('dc:date', 'dc:created'), 'datatype' => 'xsd:dateTime', - 'datatype_callback' => array('callable' => 'date_iso8601'), + 'datatype_callback' => array('callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'), )) ->save(); } diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php b/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php index c2211e3..b040e0f 100644 --- a/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php +++ b/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php @@ -11,6 +11,7 @@ use Drupal\field\Entity\FieldConfig; use Drupal\simpletest\WebTestBase; use Drupal\Core\Language\Language; +use Drupal\node\Entity\Node; /** * Tests entity translation form. @@ -55,27 +56,29 @@ function testEntityFormLanguage() { $this->drupalLogin($web_user); // Create a node with language LanguageInterface::LANGCODE_NOT_SPECIFIED. - $edit = array(); - $edit['title[0][value]'] = $this->randomName(8); - $edit['body[0][value]'] = $this->randomName(16); - - $this->drupalGet('node/add/page'); - $form_langcode = \Drupal::state()->get('entity_test.form_langcode') ?: FALSE; - $this->drupalPostForm(NULL, $edit, t('Save')); + $node = Node::create(array( + 'type' => 'page', + 'title' => $this->randomName(8), + 'body' => array( + 'value' => $this->randomName(16), + ), + 'uid' => $web_user->id(), + )); + $node->save(); - $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); + $form_langcode = \Drupal::state()->get('entity_test.form_langcode') ?: 'und'; $this->assertTrue($node->language()->id == $form_langcode, 'Form language is the same as the entity language.'); // Edit the node and test the form language. $this->drupalGet($this->langcodes[0] . '/node/' . $node->id() . '/edit'); - $form_langcode = \Drupal::state()->get('entity_test.form_langcode') ?: FALSE; + $form_langcode = \Drupal::state()->get('entity_test.form_langcode') ?: 'und'; $this->assertTrue($node->language()->id == $form_langcode, 'Form language is the same as the entity language.'); // Explicitly set form langcode. $langcode = $this->langcodes[0]; $form_state['langcode'] = $langcode; \Drupal::service('entity.form_builder')->getForm($node, 'default', $form_state); - $form_langcode = \Drupal::state()->get('entity_test.form_langcode') ?: FALSE; + $form_langcode = \Drupal::state()->get('entity_test.form_langcode') ?: 'und'; $this->assertTrue($langcode == $form_langcode, 'Form language is the same as the language parameter.'); // Enable language selector. @@ -109,7 +112,7 @@ function testEntityFormLanguage() { $node->getTranslation($langcode2)->body->value = $this->randomName(16); $node->save(); $this->drupalGet($langcode2 . '/node/' . $node->id() . '/edit'); - $form_langcode = \Drupal::state()->get('entity_test.form_langcode') ?: FALSE; + $form_langcode = \Drupal::state()->get('entity_test.form_langcode') ?: 'und'; $this->assertTrue($langcode2 == $form_langcode, "Node edit form language is $langcode2."); } } diff --git a/core/modules/taxonomy/src/Tests/LegacyTest.php b/core/modules/taxonomy/src/Tests/LegacyTest.php index 7f71d05..852ef25 100644 --- a/core/modules/taxonomy/src/Tests/LegacyTest.php +++ b/core/modules/taxonomy/src/Tests/LegacyTest.php @@ -74,8 +74,8 @@ function testTaxonomyLegacyNode() { $date = new DrupalDateTime('1969-01-01 00:00:00'); $edit = array(); $edit['title[0][value]'] = $this->randomName(); - $edit['created[date]'] = $date->format('Y-m-d'); - $edit['created[time]'] = $date->format('H:i:s'); + $edit['created[0][value][date]'] = $date->format('Y-m-d'); + $edit['created[0][value][time]'] = $date->format('H:i:s'); $edit['body[0][value]'] = $this->randomName(); $edit['field_tags'] = $this->randomName(); $this->drupalPostForm('node/add/article', $edit, t('Save and publish')); diff --git a/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWidget.php b/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWidget.php index a8afeb3..f3ffca8 100644 --- a/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWidget.php +++ b/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWidget.php @@ -18,7 +18,8 @@ * id = "text_textarea", * label = @Translation("Text area (multiple rows)"), * field_types = { - * "text_long" + * "text_long", + * "string_long", * } * ) */ diff --git a/core/modules/user/src/Plugin/Field/FieldFormatter/AuthorFormatter.php b/core/modules/user/src/Plugin/Field/FieldFormatter/AuthorFormatter.php new file mode 100644 index 0000000..38c7f55 --- /dev/null +++ b/core/modules/user/src/Plugin/Field/FieldFormatter/AuthorFormatter.php @@ -0,0 +1,50 @@ + $item) { + /** @var $referenced_user \Drupal\user\UserInterface */ + if ($referenced_user = $item->entity) { + $elements[$delta] = array( + '#theme' => 'username', + '#account' => $referenced_user, + '#link_options' => array('attributes' => array('rel' => 'author')), + '#cache' => array( + 'tags' => $referenced_user->getCacheTag(), + ), + ); + } + } + + return $elements; + } + +} diff --git a/core/modules/user/src/Plugin/Field/FieldWidget/AuthorAutocompleteWidget.php b/core/modules/user/src/Plugin/Field/FieldWidget/AuthorAutocompleteWidget.php new file mode 100644 index 0000000..43834df --- /dev/null +++ b/core/modules/user/src/Plugin/Field/FieldWidget/AuthorAutocompleteWidget.php @@ -0,0 +1,74 @@ +entity && $items[$delta]->entity->isAuthenticated() ? $items[$delta]->entity->getUsername() : ''; + + $user_config = \Drupal::config('user.settings'); + $element['target_id']['#description'] = $this->t('Leave blank for %anonymous.', array('%anonymous' => $user_config->get('anonymous'))); + + $element['target_id']['#element_validate'] = array(array($this, 'elementValidate')); + + return $element; + } + + /** + * Validates an element. + * + * @todo Convert to massageFormValues() after https://drupal.org/node/2226723 lands. + */ + public function elementValidate($element, &$form_state, $form) { + $form_builder = \Drupal::formBuilder(); + $value = $element['#value']; + // The use of empty() is mandatory in the context of usernames + // as the empty string denotes the anonymous user. In case we + // are dealing with an anonymous user we set the user ID to 0. + if (empty($value)) { + $value = 0; + } + else { + $account = user_load_by_name($value); + if ($account !== FALSE) { + $value = $account->id(); + } + else { + // Edge case: a non-existing numeric username should not be treated as + // a user ID (entity reference target_id). The ValidReference constraint + // would consider this a valid user ID, therefore we need additional + // validation here. + $form_builder->setError($element, $form_state, $this->t('The username %name does not exist.', array('%name' => $value))); + $value = NULL; + } + } + $form_builder->setValue($element, $value, $form_state); + } + +} diff --git a/core/profiles/standard/config/install/rdf.mapping.comment.node__comment.yml b/core/profiles/standard/config/install/rdf.mapping.comment.node__comment.yml index 00abf0c..d8aa944 100644 --- a/core/profiles/standard/config/install/rdf.mapping.comment.node__comment.yml +++ b/core/profiles/standard/config/install/rdf.mapping.comment.node__comment.yml @@ -11,12 +11,12 @@ fieldMappings: properties: - 'schema:dateCreated' datatype_callback: - callable: 'date_iso8601' + callable: 'Drupal\rdf\CommonDataConverter::dateIso8601Value' changed: properties: - 'schema:dateModified' datatype_callback: - callable: 'date_iso8601' + callable: 'Drupal\rdf\CommonDataConverter::dateIso8601Value' comment_body: properties: - 'schema:text' diff --git a/core/profiles/standard/config/install/rdf.mapping.node.article.yml b/core/profiles/standard/config/install/rdf.mapping.node.article.yml index 10147e7..d1b7f80 100644 --- a/core/profiles/standard/config/install/rdf.mapping.node.article.yml +++ b/core/profiles/standard/config/install/rdf.mapping.node.article.yml @@ -11,12 +11,12 @@ fieldMappings: properties: - 'schema:dateCreated' datatype_callback: - callable: 'date_iso8601' + callable: 'Drupal\rdf\CommonDataConverter::dateIso8601Value' changed: properties: - 'schema:dateModified' datatype_callback: - callable: 'date_iso8601' + callable: 'Drupal\rdf\CommonDataConverter::dateIso8601Value' body: properties: - 'schema:text' diff --git a/core/profiles/standard/config/install/rdf.mapping.node.page.yml b/core/profiles/standard/config/install/rdf.mapping.node.page.yml index 8a5d377..38120ff 100644 --- a/core/profiles/standard/config/install/rdf.mapping.node.page.yml +++ b/core/profiles/standard/config/install/rdf.mapping.node.page.yml @@ -11,12 +11,12 @@ fieldMappings: properties: - 'schema:dateCreated' datatype_callback: - callable: 'date_iso8601' + callable: 'Drupal\rdf\CommonDataConverter::dateIso8601Value' changed: properties: - 'schema:dateModified' datatype_callback: - callable: 'date_iso8601' + callable: 'Drupal\rdf\CommonDataConverter::dateIso8601Value' body: properties: - 'schema:text' diff --git a/core/themes/bartik/templates/node.html.twig b/core/themes/bartik/templates/node.html.twig index d45b0f0..7ab0b5e 100644 --- a/core/themes/bartik/templates/node.html.twig +++ b/core/themes/bartik/templates/node.html.twig @@ -23,10 +23,8 @@ * - author_picture: The node author user entity, rendered using the "compact" * view mode. * - metadata: Metadata for this node. - * - date: Formatted creation date. Preprocess functions can reformat it by - * calling format_date() with the desired parameters on - * $variables['created']. - * - author_name: Themed username of node author output from theme_username(). + * - date: Themed creation date field. + * - author_name: Themed author date field. * - url: Direct URL of the current node. * - display_submitted: Whether submission information should be displayed. * - attributes: HTML attributes for the containing element. @@ -86,7 +84,7 @@
{{ author_picture }} - {% trans %}Submitted by {{ author_name|passthrough }} on {{ date }}{% endtrans %} + {% trans %}Submitted by {{ author_name|passthrough }} on {{ date|passthrough }}{% endtrans %} {{ metadata }}