diff --git a/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php b/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php index 195e946..8793256 100644 --- a/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php +++ b/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php @@ -120,7 +120,7 @@ protected function init(array &$form_state, EntityInterface $entity, $field_name if ($entity->entityType() == 'node') { $node_type_settings = $this->nodeTypeStorage->load($entity->bundle())->getModuleSettings('node'); $options = (isset($node_type_settings['options'])) ? $node_type_settings['options'] : array(); - $entity->setNewRevision(in_array('revision', $options)); + $entity->setNewRevision(!empty($options['revision']) ? $options['revision'] : 0); $entity->log = NULL; } diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditLoadingTest.php b/core/modules/edit/lib/Drupal/edit/Tests/EditLoadingTest.php index a52faa0..73aaead 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditLoadingTest.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditLoadingTest.php @@ -246,7 +246,10 @@ public function testUserWithPermission() { // then again retrieve the field form, fill it, submit it (so it ends up // in TempStore) and then save the entity. Now there should be two // revisions. - $this->container->get('config.factory')->get('node.type.article')->set('settings.node.options', array('status', 'revision'))->save(); + $this->container->get('config.factory')->get('node.type.article')->set('settings.node.options', array( + 'status' => TRUE, + 'revision' => TRUE, + ))->save(); // Retrieve field form. $post = array('nocssjs' => 'true', 'reset' => 'true'); diff --git a/core/modules/forum/config/node.type.forum.yml b/core/modules/forum/config/node.type.forum.yml index a212cad..18a8c59 100644 --- a/core/modules/forum/config/node.type.forum.yml +++ b/core/modules/forum/config/node.type.forum.yml @@ -9,11 +9,11 @@ settings: node: preview: 1 options: - status: status + status: true # Not promoted to front page. - promote: '0' - sticky: '0' - revision: '0' + promote: false + sticky: false + revision: false submitted: true status: true langcode: en diff --git a/core/modules/node/config/schema/node.schema.yml b/core/modules/node/config/schema/node.schema.yml index c11552e..a28a2fc 100644 --- a/core/modules/node/config/schema/node.schema.yml +++ b/core/modules/node/config/schema/node.schema.yml @@ -61,16 +61,16 @@ node.settings.node: label: 'Publishing options' mapping: status: - type: string + type: boolean label: 'Published' promote: - type: string + type: boolean label: 'Promoted to front page' sticky: - type: string + type: boolean label: 'Sticky at top of lists' revision: - type: string + type: boolean label: 'Create new revision' submitted: type: boolean diff --git a/core/modules/node/lib/Drupal/node/Entity/NodeType.php b/core/modules/node/lib/Drupal/node/Entity/NodeType.php index 5bc423e..350d687 100644 --- a/core/modules/node/lib/Drupal/node/Entity/NodeType.php +++ b/core/modules/node/lib/Drupal/node/Entity/NodeType.php @@ -211,4 +211,38 @@ public static function postDelete(EntityStorageControllerInterface $storage_cont } } + /** + * {@inheritdoc} + */ + public static function preCreate(EntityStorageControllerInterface $storage_controller, array &$values) { + parent::preCreate($storage_controller, $values); + + // Ensure default values are set. + if (!isset($values['settings']['node'])) { + $values['settings']['node'] = array(); + } + $values['settings']['node'] += array( + 'options' => array( + 'status' => TRUE, + 'promote' => TRUE, + 'revision' => FALSE, + ), + 'preview' => DRUPAL_OPTIONAL, + 'submitted' => TRUE, + ); + } + + /** + * {@inheritdoc} + */ + public function getExportProperties() { + $properties = parent::getExportProperties(); + // Ensure that submitted and options are booleans. + $properties['settings']['node']['submitted'] = (bool) $properties['settings']['node']['submitted']; + foreach ($properties['settings']['node']['options'] as $key => $value) { + $properties['settings']['node']['options'][$key] = (bool) $value; + } + return $properties; + } + } diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index a787175..30519b3 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -43,7 +43,7 @@ protected function prepareEntity() { foreach (array('status', 'promote', 'sticky') as $key) { // Multistep node forms might have filled in something already. if ($node->$key->isEmpty()) { - $node->$key = (int) in_array($key, $this->settings['options']); + $node->$key = (int) (isset($this->settings['options'][$key]) ? $this->settings['options'][$key] : 0); } } global $user; @@ -56,7 +56,7 @@ protected function prepareEntity() { $node->log = NULL; } // Always use the default revision setting. - $node->setNewRevision(in_array('revision', $this->settings['options'])); + $node->setNewRevision(isset($this->settings['options']['revision']) ? $this->settings['options']['revision'] : FALSE); } /** diff --git a/core/modules/node/lib/Drupal/node/NodeTypeFormController.php b/core/modules/node/lib/Drupal/node/NodeTypeFormController.php index d9d5666..ef213a3 100644 --- a/core/modules/node/lib/Drupal/node/NodeTypeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeTypeFormController.php @@ -8,6 +8,7 @@ namespace Drupal\node; use Drupal\Core\Entity\EntityFormController; +use Drupal\Component\Utility\MapArray; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -30,13 +31,6 @@ public function form(array $form, array &$form_state) { } $node_settings = $type->getModuleSettings('node'); - // Ensure default settings. - $node_settings += array( - 'options' => array('status', 'promote'), - 'preview' => DRUPAL_OPTIONAL, - 'submitted' => TRUE, - ); - $form['name'] = array( '#title' => t('Name'), '#type' => 'textfield', @@ -118,7 +112,7 @@ public function form(array $form, array &$form_state) { $form['workflow']['options'] = array('#type' => 'checkboxes', '#title' => t('Default options'), '#parents' => array('settings', 'node', 'options'), - '#default_value' => $node_settings['options'], + '#default_value' => MapArray::copyValuesToKeys(array_keys(array_filter($node_settings['options']))), '#options' => array( 'status' => t('Published'), 'promote' => t('Promoted to front page'), diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php index 090a27e..acf281b 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php @@ -55,6 +55,19 @@ function testNodeCreation() { // Check that the node exists in the database. $node = $this->drupalGetNodeByTitle($edit["title"]); $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); + + // Change the node type setting to show submitted by information. + $node_type = entity_load('node_type', 'page'); + $node_type->settings['node']['submitted'] = TRUE; + $node_type->save(); + + $this->drupalGet('node/' . $node->id()); + $this->assertText($submitted_by); } /** diff --git a/core/modules/node/lib/Drupal/node/Tests/NodePostSettingsTest.php b/core/modules/node/lib/Drupal/node/Tests/NodePostSettingsTest.php index d213a69..51299c6 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodePostSettingsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodePostSettingsTest.php @@ -61,6 +61,7 @@ function testPagePostInfo() { $this->drupalPostForm('node/add/page', $edit, t('Save')); // Check that the post information is displayed. - $this->assertNoRaw('', 'Post information is not displayed.'); + $elements = $this->xpath('//*[contains(@class,:class)]', array(':class' => 'submitted')); + $this->assertEqual(count($elements), 0, 'Post information is not displayed.'); } } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTestBase.php b/core/modules/node/lib/Drupal/node/Tests/NodeTestBase.php index 1043fb6..a4d4a80 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTestBase.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTestBase.php @@ -27,7 +27,7 @@ function setUp() { // Create Basic page and Article node types. if ($this->profile != 'standard') { - $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); + $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page', 'settings' => array('node' => array('submitted' => FALSE)))); $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); } } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 772481b9..8cd417f 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -702,8 +702,7 @@ function template_preprocess_node(&$variables) { // Display post information only on certain node types. // Avoid loading the entire node type config entity here. - $submitted = \Drupal::config('node.type.' . $node->bundle())->get('settings.node.submitted') ?: TRUE; - if ($submitted) { + if (\Drupal::config('node.type.' . $node->bundle())->get('settings.node.submitted')) { $variables['display_submitted'] = TRUE; $variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date'])); if (theme_get_setting('features.node_user_picture')) { diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/StandardProfileTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/StandardProfileTest.php index 9feaa50..8817644 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/StandardProfileTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/StandardProfileTest.php @@ -284,7 +284,9 @@ protected function doArticleRdfaTests() { protected function doPageRdfaTests() { // The standard profile hides the created date on pages. Revert display to // true for testing. - variable_set('node_submitted_page', TRUE); + $node_type = entity_load('node_type', 'page'); + $node_type->settings['node']['submitted'] = TRUE; + $node_type->save(); // Feed the HTML into the parser. $uri_info = $this->page->uri(); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index a307e32..58df43f 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -288,6 +288,10 @@ protected function drupalCreateNode(array $settings = array()) { 'format' => filter_default_format(), ); + // If the specified node type does not exist, create it. + if (!$this->container->get('entity.query')->get('node_type')->condition('type', $settings['type'])->execute()) { + $this->drupalCreateContentType(array('type' => $settings['type'], 'name' => $this->randomString())); + } $node = entity_create('node', $settings); if (!empty($settings['revision'])) { $node->setNewRevision(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php index 3487fd4..92e7f2b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php @@ -172,7 +172,7 @@ function testLinkRenderArrayText() { * * @param $link * URL to search. - * @param $class + * @papam $class * Element class to search for. * * @return bool diff --git a/core/profiles/standard/config/node.type.article.yml b/core/profiles/standard/config/node.type.article.yml index dd2394f..a3e10b2 100644 --- a/core/profiles/standard/config/node.type.article.yml +++ b/core/profiles/standard/config/node.type.article.yml @@ -9,10 +9,10 @@ settings: node: preview: '1' options: - status: status - promote: promote - sticky: '0' - revision: '0' - submitted: '1' + status: true + promote: true + sticky: false + revision: false + submitted: true status: '1' langcode: en diff --git a/core/profiles/standard/config/node.type.page.yml b/core/profiles/standard/config/node.type.page.yml index 48a919a..d41ae94 100644 --- a/core/profiles/standard/config/node.type.page.yml +++ b/core/profiles/standard/config/node.type.page.yml @@ -9,10 +9,10 @@ settings: node: preview: '1' options: - status: status - promote: '0' - sticky: '0' - revision: '0' - submitted: '0' + status: true + promote: false + sticky: false + revision: false + submitted: false status: '1' langcode: en