diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/AuthorAutocompleteWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/AuthorAutocompleteWidget.php index a331fe6..4454049 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/AuthorAutocompleteWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/AuthorAutocompleteWidget.php @@ -46,7 +46,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen /** * Validates an element. * - * @todo Convert to massageFormValues() override once that actually works. + * @todo Convert to massageFormValues() after https://drupal.org/node/2226723 lands. */ public function elementValidate($element, &$form_state, $form) { $value = $element['#value']; @@ -57,10 +57,13 @@ public function elementValidate($element, &$form_state, $form) { $value = 0; } else { - $account = user_load_by_name($element['#value']); + $account = user_load_by_name($value); if ($account !== FALSE) { $value = $account->id(); } + else { + $value = -1; + } } form_set_value($element, $value, $form_state); } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/TimestampWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/TimestampWidget.php index 9856ca3..1d27fe7 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/TimestampWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/TimestampWidget.php @@ -20,7 +20,10 @@ * field_types = { * "timestamp", * "created", - * } + * }, + * settings = { + * "use_request_time_on_empty" = FALSE, + * }, * ) */ class TimestampWidget extends WidgetBase { @@ -50,18 +53,17 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen /** * Validates an element. * - * @todo Convert to massageFormValues() override once that actually works. + * @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 = 0; + $value = $this->getSetting('use_request_time_on_empty') ? REQUEST_TIME : 0; } else { $date = new DrupalDateTime($value); if ($date->hasErrors()) { - $value = -1; - // $this->setFormError('') + $value = FALSE; } else { $value = $date->getTimestamp(); diff --git a/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldWidget/DateTimeTimestampWidget.php b/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldWidget/DateTimeTimestampWidget.php index a9310ef..395dd81 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldWidget/DateTimeTimestampWidget.php +++ b/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldWidget/DateTimeTimestampWidget.php @@ -47,7 +47,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen /** * Validates an element. * - * @todo Convert to massageFormValues() override once that actually works. + * @todo Convert to massageFormValues() after https://drupal.org/node/2226723 lands. */ public function elementValidate($element, &$form_state, $form) { $date = $element['#value']['object']; diff --git a/core/modules/node/lib/Drupal/node/Entity/Node.php b/core/modules/node/lib/Drupal/node/Entity/Node.php index 9ed416b..78e1dd9 100644 --- a/core/modules/node/lib/Drupal/node/Entity/Node.php +++ b/core/modules/node/lib/Drupal/node/Entity/Node.php @@ -356,13 +356,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['langcode'] = FieldDefinition::create('language') ->setLabel(t('Language')) ->setDescription(t('The node language code.')) - ->setRevisionable(TRUE) - ->setCardinality(1) - ->setDisplayOptions('form', array( - 'type' => 'language', - 'weight' => 0, - )) - ->setDisplayConfigurable('form', TRUE); + ->setRevisionable(TRUE); $fields['title'] = FieldDefinition::create('string') ->setLabel(t('Title')) @@ -390,7 +384,6 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setDescription(t('The user ID of the node author.')) ->setRevisionable(TRUE) ->setTranslatable(TRUE) - ->setCardinality(1) ->setSettings(array( 'target_type' => 'user', 'default_value' => 0, @@ -412,15 +405,13 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setLabel(t('Publishing status')) ->setDescription(t('A boolean indicating whether the node is published.')) ->setRevisionable(TRUE) - ->setTranslatable(TRUE) - ->setCardinality(1); + ->setTranslatable(TRUE); $fields['created'] = FieldDefinition::create('created') ->setLabel(t('Publication date')) ->setDescription(t('The time that the node was created.')) ->setRevisionable(TRUE) ->setTranslatable(TRUE) - ->setCardinality(1) ->setDisplayOptions('view', array( 'label' => 'hidden', 'type' => 'timestamp', @@ -429,6 +420,9 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setDisplayOptions('form', array( 'type' => 'timestamp', 'weight' => 0, + 'settings' => array( + 'use_request_time_on_empty' => TRUE, + ), )) ->setDisplayConfigurable('form', TRUE); @@ -452,7 +446,6 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setLabel(t('Sticky at top of lists')) ->setRevisionable(TRUE) ->setTranslatable(TRUE) - ->setCardinality(1) ->setDisplayOptions('form', array( 'type' => 'boolean', 'weight' => 0, @@ -472,9 +465,8 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setQueryable(FALSE) ->setRevisionable(TRUE); - $fields['log'] = FieldDefinition::create('string') + $fields['log'] = FieldDefinition::create('string_long') ->setLabel(t('Revision log message')) - ->setCardinality(1) ->setDescription(t('Briefly describe the changes you have made.')) ->setRevisionable(TRUE) ->setTranslatable(TRUE) @@ -504,15 +496,14 @@ public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, // Set a widget for the 'langcode' base field if Language module is enabled // and the bundle has multilingual support. if (\Drupal::moduleHandler()->moduleExists('language')) { - foreach (node_type_get_types() as $bundle) { - $configuration = language_get_default_configuration('node', $bundle->type); - if ($configuration['language_show']) { - $fields['langcode'] = clone $base_field_definitions['langcode']; - $fields['langcode']->setDisplayOptions('form', array( - 'type' => 'language', - 'weight' => 0, - )); - } + $configuration = language_get_default_configuration('node', $bundle); + if ($configuration['language_show']) { + $fields['langcode'] = clone $base_field_definitions['langcode']; + $fields['langcode']->setDisplayOptions('form', array( + 'type' => 'language', + 'weight' => 0, + )) + ->setDisplayConfigurable('form', TRUE); } } diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index fb05d6b..f18bd03 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -289,11 +289,6 @@ public function validate(array $form, array &$form_state) { $this->setFormError('uid', $form_state, $this->t('The username %name does not exist.', array('%name' => $form_state['values']['uid'][0]['value']))); } - // Validate the "authored on" field. - if ($form_state['values']['created'][0]['value'] < 0) { - $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. @@ -391,16 +386,9 @@ public function buildEntity(array $form, array &$form_state) { $entity->setOwnerId($form_state['values']['uid'][0]['value']); - if ($form_state['values']['created'][0]['value'] >= 0) { - $entity->setCreatedTime($form_state['values']['created'][0]['value']); - } - else { - $entity->setCreatedTime(REQUEST_TIME); - } return $entity; } - /** * Overrides Drupal\Core\Entity\EntityFormController::save(). */ diff --git a/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php b/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php index 67bdbe3..5620a8f 100644 --- a/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php @@ -62,13 +62,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/taxonomy/lib/Drupal/taxonomy/Tests/LegacyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LegacyTest.php index 37a1f53..b45c929 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LegacyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LegacyTest.php @@ -38,8 +38,8 @@ function testTaxonomyLegacyNode() { $date = new DrupalDateTime('1969-01-01 00:00:00'); $edit = array(); $edit['title[0][value]'] = $this->randomName(); - $edit['created[0][value][date]'] = $date->format($date_format); - $edit['created[0][value][time]'] = $date->format($time_format); + $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/lib/Drupal/text/Plugin/Field/FieldWidget/TextareaWidget.php b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldWidget/TextareaWidget.php index 7785369..8474b2b 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldWidget/TextareaWidget.php +++ b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldWidget/TextareaWidget.php @@ -19,7 +19,7 @@ * label = @Translation("Text area (multiple rows)"), * field_types = { * "text_long", - * "string", + * "string_long", * }, * settings = { * "rows" = "5",