diff --git a/core/modules/book/config/install/node.type.book.yml b/core/modules/book/config/install/node.type.book.yml index e61498f..172eaaf 100644 --- a/core/modules/book/config/install/node.type.book.yml +++ b/core/modules/book/config/install/node.type.book.yml @@ -2,11 +2,8 @@ type: book name: 'Book page' description: 'Books have a built-in hierarchical navigation. Use for handbooks or tutorials.' help: '' -settings: - node: - preview: 1 - options: - revision: false - submitted: true +new_revision: false +display_submitted: true +preview_mode: 1 status: true langcode: en diff --git a/core/modules/forum/config/install/node.type.forum.yml b/core/modules/forum/config/install/node.type.forum.yml index df4ce2e..f7833f7 100644 --- a/core/modules/forum/config/install/node.type.forum.yml +++ b/core/modules/forum/config/install/node.type.forum.yml @@ -2,11 +2,8 @@ type: forum name: 'Forum topic' description: 'A forum topic starts a new discussion thread within a forum.' help: '' -settings: - node: - preview: 1 - options: - revision: false - submitted: true +new_revision: false +display_submitted: true +preview_mode: 1 status: true langcode: en diff --git a/core/modules/menu_ui/config/schema/menu_ui.schema.yml b/core/modules/menu_ui/config/schema/menu_ui.schema.yml index 7625f0d..7855ba3 100644 --- a/core/modules/menu_ui/config/schema/menu_ui.schema.yml +++ b/core/modules/menu_ui/config/schema/menu_ui.schema.yml @@ -14,7 +14,7 @@ menu_ui.settings: type: boolean label: 'Override parent selector' -menu.entity.node.*: +node_type.third_party.menu_ui: type: mapping label: 'Per-content type menu settings' mapping: diff --git a/core/modules/menu_ui/menu_ui.install b/core/modules/menu_ui/menu_ui.install index 0e580b4..a75a02c 100644 --- a/core/modules/menu_ui/menu_ui.install +++ b/core/modules/menu_ui/menu_ui.install @@ -5,8 +5,6 @@ * Install, update and uninstall functions for the menu_ui module. */ -use Drupal\Component\Uuid\Uuid; - /** * Implements hook_install(). */ @@ -17,15 +15,6 @@ function menu_ui_install() { // \Drupal\Core\Extension\ModuleHandler::install(). // @see https://drupal.org/node/2181151 \Drupal::service('router.builder')->rebuild(); - if (\Drupal::moduleHandler()->moduleExists('node')) { - $node_types = array_keys(node_type_get_names()); - foreach ($node_types as $type_id) { - \Drupal::config('menu.entity.node.' . $type_id) - ->set('available_menus', array('main')) - ->set('parent', 'main:0') - ->save(); - } - } } /** diff --git a/core/modules/menu_ui/menu_ui.module b/core/modules/menu_ui/menu_ui.module index 820887a..1dfd3ff 100644 --- a/core/modules/menu_ui/menu_ui.module +++ b/core/modules/menu_ui/menu_ui.module @@ -166,29 +166,6 @@ function menu_ui_node_update(EntityInterface $node) { } /** - * Implements hook_ENTITY_TYPE_insert() for node_type entities. - */ -function menu_ui_node_type_insert(NodeTypeInterface $type) { - if ($type->isSyncing()) { - return; - } - \Drupal::config('menu.entity.node.' . $type->id()) - ->set('available_menus', array('main')) - ->set('parent', 'main:') - ->save(); -} - -/** - * Implements hook_ENTITY_TYPE_delete() for node_type entities. - */ -function menu_ui_node_type_delete(NodeTypeInterface $type) { - if ($type->isSyncing()) { - return; - } - \Drupal::config('menu.entity.node.' . $type->id())->delete(); -} - -/** * Helper for hook_ENTITY_TYPE_insert() and hook_ENTITY_TYPE_update() for nodes. */ function menu_ui_node_save(EntityInterface $node) { @@ -251,13 +228,14 @@ function menu_ui_node_predelete(EntityInterface $node) { function menu_ui_node_prepare_form(NodeInterface $node, $operation, FormStateInterface $form_state) { if (empty($form_state['menu_link_definition'])) { // Prepare the node for the edit form so that $node->menu always exists. - $node_type_config = \Drupal::config('menu.entity.node.' . $node->getType()); - $menu_name = strtok($node_type_config->get('parent'), ':'); + /** @var \Drupal\node\NodeTypeInterface $node_type */ + $node_type = $node->type->entity; + $menu_name = strtok($node_type->getThirdPartySetting('menu_ui', 'parent', 'main:'), ':'); $definition = FALSE; if ($node->id()) { $id = FALSE; // Give priority to the default menu - $type_menus = $node_type_config->get('available_menus'); + $type_menus = $node_type->getThirdPartySetting('menu_ui', 'available_menus', array('main')); if (in_array($menu_name, $type_menus)) { $query = \Drupal::entityQuery('menu_link_content') ->condition('route_name', 'entity.node.canonical') @@ -323,11 +301,12 @@ function menu_ui_form_node_form_alter(&$form, FormStateInterface $form_state) { // @todo This must be handled in a #process handler. $node = $form_state->getFormObject()->getEntity(); $definition = $form_state['menu_link_definition']; - $type = $node->getType(); + /** @var \Drupal\node\NodeTypeInterface $node_type */ + $node_type = $node->type->entity; /** @var \Drupal\Core\Menu\MenuParentFormSelectorInterface $menu_parent_selector */ $menu_parent_selector = \Drupal::service('menu.parent_form_selector'); $menu_names = menu_ui_get_menus(); - $type_menus = \Drupal::config("menu.entity.node.$type")->get('available_menus'); + $type_menus = $node_type->getThirdPartySetting('menu_ui', 'available_menus', array('main')); $available_menus = array(); foreach ($type_menus as $menu) { $available_menus[$menu] = $menu_names[$menu]; @@ -336,7 +315,7 @@ function menu_ui_form_node_form_alter(&$form, FormStateInterface $form_state) { $default = $definition['menu_name'] . ':' . $definition['parent']; } else { - $default = \Drupal::config('menu.entity.node.'.$type)->get('parent'); + $default = $node_type->getThirdPartySetting('menu_ui', 'parent', 'main:'); } $parent_element = $menu_parent_selector->parentSelectElement($default, $definition['id'], $available_menus); // If no possible parent menu items were found, there is nothing to display. @@ -446,16 +425,8 @@ function menu_ui_form_node_type_form_alter(&$form, FormStateInterface $form_stat /** @var \Drupal\Core\Menu\MenuParentFormSelectorInterface $menu_parent_selector */ $menu_parent_selector = \Drupal::service('menu.parent_form_selector'); $menu_options = menu_ui_get_menus(); + /** @var \Drupal\node\NodeTypeInterface $type */ $type = $form_state->getFormObject()->getEntity(); - if ($type->id()) { - $config_values = \Drupal::config('menu.entity.node.' . $type->id())->get(); - } - else { - $config_values = array( - 'available_menus' => array('main'), - 'parent' => 'main:', - ); - } $form['menu'] = array( '#type' => 'details', '#title' => t('Menu settings'), @@ -467,7 +438,7 @@ function menu_ui_form_node_type_form_alter(&$form, FormStateInterface $form_stat $form['menu']['menu_options'] = array( '#type' => 'checkboxes', '#title' => t('Available menus'), - '#default_value' => $config_values['available_menus'], + '#default_value' => $type->getThirdPartySetting('menu_ui', 'available_menus', array('main')), '#options' => $menu_options, '#description' => t('The menus available to place links in for this content type.'), ); @@ -480,14 +451,14 @@ function menu_ui_form_node_type_form_alter(&$form, FormStateInterface $form_stat $form['menu']['menu_parent'] = array( '#type' => 'select', '#title' => t('Default parent item'), - '#default_value' => $config_values['parent'], + '#default_value' => $type->getThirdPartySetting('menu_ui', 'parent', 'main:'), '#options' => $options, '#description' => t('Choose the menu item to be the default parent for a new link in the content authoring form.'), '#attributes' => array('class' => array('menu-title-select')), ); $form['actions']['submit']['#validate'][] = 'menu_ui_form_node_type_form_validate'; - $form['actions']['submit']['#submit'][] = 'menu_ui_form_node_type_form_submit'; + $form['#entity_builders'][] = 'menu_ui_form_node_type_form_builder'; } /** @@ -511,16 +482,13 @@ function menu_ui_form_node_type_form_validate(&$form, FormStateInterface $form_s } /** - * Submit handler for forms with menu options. + * Entity builder for the node type form with menu options. * * @see menu_ui_form_node_type_form_alter(). */ -function menu_ui_form_node_type_form_submit(&$form, FormStateInterface $form_state) { - $type = $form_state->getFormObject()->getEntity(); - \Drupal::config('menu.entity.node.' . $type->id()) - ->set('available_menus', array_values(array_filter($form_state->getValue('menu_options')))) - ->set('parent', $form_state->getValue('menu_parent')) - ->save(); +function menu_ui_form_node_type_form_builder($entity_type, NodeTypeInterface $type, &$form, FormStateInterface $form_state) { + $type->setThirdPartySetting('menu_ui', 'available_menus', array_values(array_filter($form_state->getValue('menu_options')))); + $type->setThirdPartySetting('menu_ui', 'parent', $form_state->getValue('menu_parent')); } /** diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_node_type.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_node_type.yml index 609f391..a1c5f3c 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_node_type.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_node_type.yml @@ -14,8 +14,9 @@ process: description: description help: help title_label: title_label - 'settings/node/preview': 'constants/preview' - 'settings/node/submitted': submitted + 'preview_mode': 'constants/preview' + 'display_submitted': display_submitted + 'new_revision': 'options/revision' 'settings/node/options': options create_body: has_body create_body_label: body_label diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/NodeType.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/NodeType.php index 665cc13..3b2e443 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/NodeType.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/NodeType.php @@ -110,7 +110,7 @@ public function prepareRow(Row $row) { } $row->setSourceProperty('options', $options); $submitted = isset($this->themeSettings['toggle_node_info_' . $type]) ? $this->themeSettings['toggle_node_info_' . $type] : FALSE; - $row->setSourceProperty('submitted', $submitted); + $row->setSourceProperty('display_submitted', $submitted); return parent::prepareRow($row); } diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateNodeTypeTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateNodeTypeTest.php index 4ec8f0e..cd396aa 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateNodeTypeTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateNodeTypeTest.php @@ -52,16 +52,9 @@ public function testNodeType() { // Test the test_page content type. $node_type_page = entity_load('node_type', 'test_page'); $this->assertEqual($node_type_page->id(), 'test_page', 'Node type test_page loaded'); - $expected = array( - 'options' => array( - 'revision' => FALSE, - ), - 'preview' => 1, - 'submitted' => TRUE, - ); - - // @todo: Fix due to https://www.drupal.org/node/2283977 - // $this->assertEqual($node_type_page->settings['node'], $expected, 'Node type test_page settings correct.'); + $this->assertEqual($node_type_page->displaySubmitted(), TRUE); + $this->assertEqual($node_type_page->isNewRevision(), FALSE); + $this->assertEqual($node_type_page->getPreviewMode(), DRUPAL_OPTIONAL); $this->assertEqual(array('test_page'), $migration->getIdMap()->lookupDestinationID(array('test_page'))); // Test we have a body field. @@ -71,15 +64,9 @@ public function testNodeType() { // Test the test_story content type. $node_type_story = entity_load('node_type', 'test_story'); $this->assertEqual($node_type_story->id(), 'test_story', 'Node type test_story loaded'); - $expected = array( - 'options' => array( - 'revision' => FALSE, - ), - 'preview' => 1, - 'submitted' => TRUE, - ); - // @todo: Fix due to https://www.drupal.org/node/2283977 - // $this->assertEqual($node_type_story->settings['node'], $expected, 'Node type test_story settings correct.'); + $this->assertEqual($node_type_story->displaySubmitted(), TRUE); + $this->assertEqual($node_type_story->isNewRevision(), FALSE); + $this->assertEqual($node_type_story->getPreviewMode(), DRUPAL_OPTIONAL); $this->assertEqual(array('test_story'), $migration->getIdMap()->lookupDestinationID(array('test_story'))); // Test we don't have a body field. @@ -89,16 +76,9 @@ public function testNodeType() { // Test the test_event content type. $node_type_event = entity_load('node_type', 'test_event'); $this->assertEqual($node_type_event->id(), 'test_event', 'Node type test_event loaded'); - $expected = array( - 'options' => array( - 'revision' => TRUE, - ), - 'preview' => 1, - 'submitted' => TRUE, - ); - - // @todo: Fix due to https://www.drupal.org/node/2283977 - // $this->assertEqual($node_type_event->settings['node'], $expected, 'Node type test_event settings correct.'); + $this->assertEqual($node_type_event->displaySubmitted(), TRUE); + $this->assertEqual($node_type_event->isNewRevision(), TRUE); + $this->assertEqual($node_type_event->getPreviewMode(), DRUPAL_OPTIONAL); $this->assertEqual(array('test_event'), $migration->getIdMap()->lookupDestinationID(array('test_event'))); // Test we have a body field. diff --git a/core/modules/node/config/schema/node.schema.yml b/core/modules/node/config/schema/node.schema.yml index 428ffc7..0680b57 100644 --- a/core/modules/node/config/schema/node.schema.yml +++ b/core/modules/node/config/schema/node.schema.yml @@ -27,39 +27,20 @@ node.type.*: help: type: text label: 'Explanation or submission guidelines' - settings: - type: mapping - label: 'Settings' - mapping: - node: - type: node.settings.node - -node.settings.node: - type: mapping - label: 'Content type settings' - mapping: - preview: + new_revision: + type: boolean + label: 'Whether a new revision should be created by default' + preview_mode: type: integer label: 'Preview before submitting' - options: - type: mapping - label: 'Publishing options' - mapping: - status: - type: boolean - label: 'Published' - promote: - type: boolean - label: 'Promoted to front page' - sticky: - type: boolean - label: 'Sticky at top of lists' - revision: - type: boolean - label: 'Create new revision' - submitted: + display_submitted: type: boolean label: 'Display setting for author and date Submitted by post information' + third_party_settings: + type: sequence + label: 'Third party settings' + sequence: + - type: node_type.third_party.[%key] # Plugin \Drupal\node\Plugin\Search\NodeSearch search.plugin.node_search: diff --git a/core/modules/node/node.module b/core/modules/node/node.module index d96052d..62894ef 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -635,11 +635,10 @@ function template_preprocess_node(&$variables) { // Display post information only on certain node types. // Avoid loading the entire node type config entity here that may not exist. - $node_type_config = \Drupal::config('node.type.' . $node->bundle()); + $node_type = $node->type->entity; // Used by RDF to add attributes around the author and date submitted. $variables['author_attributes'] = new Attribute(); - // Display submitted by default. - $variables['display_submitted'] = $node_type_config->isNew() || $node_type_config->get('settings.node.submitted'); + $variables['display_submitted'] = $node_type->displaySubmitted(); if ($variables['display_submitted']) { if (theme_get_setting('features.node_user_picture')) { // To change user picture settings (e.g. image style), edit the 'compact' diff --git a/core/modules/node/src/Entity/NodeType.php b/core/modules/node/src/Entity/NodeType.php index 22f66d4..89d5540 100644 --- a/core/modules/node/src/Entity/NodeType.php +++ b/core/modules/node/src/Entity/NodeType.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Config\Entity\ConfigEntityBundleBase; +use Drupal\Core\Config\Entity\ThirdPartySettingsTrait; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\node\NodeTypeInterface; @@ -41,6 +42,7 @@ * ) */ class NodeType extends ConfigEntityBundleBase implements NodeTypeInterface { + use ThirdPartySettingsTrait; /** * The machine name of this node type. @@ -75,6 +77,27 @@ class NodeType extends ConfigEntityBundleBase implements NodeTypeInterface { public $help; /** + * Default value of the 'Create new revision' checkbox of this node type. + * + * @var bool + */ + protected $new_revision = FALSE; + + /** + * The preview mode. + * + * @var int + */ + protected $preview_mode = DRUPAL_OPTIONAL; + + /** + * Display setting for author and date Submitted by post information. + * + * @var bool + */ + protected $display_submitted = TRUE; + + /** * Indicates whether a Body field should be created for this node type. * * This property affects entity creation only. It allows default configuration @@ -97,37 +120,60 @@ class NodeType extends ConfigEntityBundleBase implements NodeTypeInterface { protected $create_body_label = 'Body'; /** - * Module-specific settings for this node type, keyed by module name. - * - * @var array - * - * @todo Pluginify. + * {@inheritdoc} */ - public $settings = array(); + public function id() { + return $this->type; + } /** * {@inheritdoc} */ - public function id() { - return $this->type; + public function isLocked() { + $locked = \Drupal::state()->get('node.type.locked'); + return isset($locked[$this->id()]) ? $locked[$this->id()] : FALSE; } /** * {@inheritdoc} */ - public function getModuleSettings($module) { - if (isset($this->settings[$module]) && is_array($this->settings[$module])) { - return $this->settings[$module]; - } - return array(); + public function isNewRevision() { + return $this->new_revision; } /** * {@inheritdoc} */ - public function isLocked() { - $locked = \Drupal::state()->get('node.type.locked'); - return isset($locked[$this->id()]) ? $locked[$this->id()] : FALSE; + public function setNewRevision($new_revision) { + $this->new_revision = $new_revision; + } + + /** + * {@inheritdoc} + */ + public function displaySubmitted() { + return $this->display_submitted; + } + + /** + * {@inheritdoc} + */ + public function setDisplaySubmitted($display_submtited) { + $this->display_submitted = $display_submtited; + } + + /** + * {@inheritdoc} + */ + public function getPreviewMode() { + return $this->preview_mode; + } + + /** + * {@inheritdoc} + */ + public function setPreviewMode($preview_mode) { + $this->preview_mode = $preview_mode; } /** @@ -173,23 +219,4 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti $storage->resetCache(array_keys($entities)); } - /** - * {@inheritdoc} - */ - public static function preCreate(EntityStorageInterface $storage, array &$values) { - parent::preCreate($storage, $values); - - // Ensure default values are set. - if (!isset($values['settings']['node'])) { - $values['settings']['node'] = array(); - } - $values['settings']['node'] = NestedArray::mergeDeep(array( - 'options' => array( - 'revision' => FALSE, - ), - 'preview' => DRUPAL_OPTIONAL, - 'submitted' => TRUE, - ), $values['settings']['node']); - } - } diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php index 5bf0506..b521bdb 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -23,13 +23,6 @@ class NodeForm extends ContentEntityForm { /** - * Default settings for this content/node type. - * - * @var array - */ - protected $settings; - - /** * The tempstore factory. * * @var \Drupal\user\TempStoreFactory @@ -65,9 +58,6 @@ public static function create(ContainerInterface $container) { protected function prepareEntity() { /** @var \Drupal\node\NodeInterface $node */ $node = $this->entity; - // Set up default values, if required. - $type = entity_load('node_type', $node->bundle()); - $this->settings = $type->getModuleSettings('node'); if (!$node->isNew()) { $node->date = format_date($node->getCreatedTime(), 'custom', 'Y-m-d H:i:s O'); @@ -156,7 +146,7 @@ public function form(array $form, FormStateInterface $form_state) { $form['revision'] = array( '#type' => 'checkbox', '#title' => t('Create new revision'), - '#default_value' => !empty($this->settings['options']['revision']), + '#default_value' => $node->type->entity->isNewRevision(), '#access' => $node->isNewRevision() || $current_user->hasPermission('administer nodes'), '#group' => 'revision_information', ); @@ -258,7 +248,7 @@ public function form(array $form, FormStateInterface $form_state) { protected function actions(array $form, FormStateInterface $form_state) { $element = parent::actions($form, $form_state); $node = $this->entity; - $preview_mode = $this->settings['preview']; + $preview_mode = $node->type->entity->getPreviewMode(); $element['submit']['#access'] = $preview_mode != DRUPAL_REQUIRED || (!form_get_errors($form_state) && isset($form_state['node_preview'])); diff --git a/core/modules/node/src/NodeTypeForm.php b/core/modules/node/src/NodeTypeForm.php index 4088154..8694501 100644 --- a/core/modules/node/src/NodeTypeForm.php +++ b/core/modules/node/src/NodeTypeForm.php @@ -68,7 +68,6 @@ public function form(array $form, FormStateInterface $form_state) { $node = $this->entityManager->getStorage('node')->create(array('type' => $type->id())); } - $node_settings = $type->getModuleSettings('node'); $form['name'] = array( '#title' => t('Name'), '#type' => 'textfield', @@ -118,11 +117,10 @@ public function form(array $form, FormStateInterface $form_state) { '#default_value' => $fields['title']->getLabel(), '#required' => TRUE, ); - $form['submission']['preview'] = array( + $form['submission']['preview_mode'] = array( '#type' => 'radios', '#title' => t('Preview before submitting'), - '#parents' => array('settings', 'node', 'preview'), - '#default_value' => $node_settings['preview'], + '#default_value' => $type->getPreviewMode(), '#options' => array( DRUPAL_DISABLED => t('Disabled'), DRUPAL_OPTIONAL => t('Optional'), @@ -144,7 +142,7 @@ public function form(array $form, FormStateInterface $form_state) { 'status' => $node->status->value, 'promote' => $node->promote->value, 'sticky' => $node->sticky->value, - 'revision' => $type->settings['node']['options']['revision'], + 'revision' => $type->isNewRevision(), ); // Prepare workflow options to be used for 'checkboxes' form element. $keys = array_keys(array_filter($workflow_options)); @@ -182,11 +180,10 @@ public function form(array $form, FormStateInterface $form_state) { '#title' => t('Display settings'), '#group' => 'additional_settings', ); - $form['display']['submitted'] = array( + $form['display']['display_submitted'] = array( '#type' => 'checkbox', '#title' => t('Display author and date information.'), - '#parents' => array('settings', 'node', 'submitted'), - '#default_value' => $node_settings['submitted'], + '#default_value' => $type->displaySubmitted(), '#description' => t('Author username and publish date will be displayed.'), ); return $form; @@ -220,7 +217,7 @@ public function validate(array $form, FormStateInterface $form_state) { */ public function save(array $form, FormStateInterface $form_state) { $type = $this->entity; - $type->settings['node']['options']['revision'] = $form_state['values']['options']['revision']; + $type->setNewRevision($form_state->getValue(array('options', 'revision'))); $type->type = trim($type->id()); $type->name = trim($type->name); diff --git a/core/modules/node/src/NodeTypeInterface.php b/core/modules/node/src/NodeTypeInterface.php index d828feb..d113f87 100644 --- a/core/modules/node/src/NodeTypeInterface.php +++ b/core/modules/node/src/NodeTypeInterface.php @@ -8,30 +8,67 @@ namespace Drupal\node; use Drupal\Core\Config\Entity\ConfigEntityInterface; +use Drupal\Core\Config\Entity\ThirdPartySettingsInterface; /** * Provides an interface defining a node type entity. */ -interface NodeTypeInterface extends ConfigEntityInterface { +interface NodeTypeInterface extends ConfigEntityInterface, ThirdPartySettingsInterface { /** - * Returns the configured node type settings of a given module, if any. + * Determines whether the node type is locked. * - * @param string $module - * The name of the module whose settings to return. + * @return string|false + * The module name that locks the type or FALSE. + */ + public function isLocked(); + + /** + * Returns whether a new revision should be created by default. * - * @return array - * An associative array containing the module's settings for the node type. - * Note that this can be empty, and default values do not necessarily exist. + * @return bool + * TRUE if a new revision should be created by default. */ - public function getModuleSettings($module); + public function isNewRevision(); /** - * Determines whether the node type is locked. + * Set whether a new revision should be created by default. * - * @return string|false - * The module name that locks the type or FALSE. + * @param bool $new_revision_ + * TRUE if a new revision should be created by default. */ - public function isLocked(); + public function setNewRevision($new_revision); + + /** + * Returns whether 'Submitted by' information should be shown. + * + * @return bool + * TRUE if the submitted by information should be shown. + */ + public function displaySubmitted(); + + /** + * Set whether 'Submitted by' information should be shown. + * + * @param bool $display_submitted + * TRUE if the submitted by information should be shown. + */ + public function setDisplaySubmitted($display_submtited); + + /** + * Returns the preview mode. + * + * @return int + * DRUPAL_DISABLED, DRUPAL_OPTIONAL or DRUPAL_REQUIRED. + */ + public function getPreviewMode(); + + /** + * Sets the preview mode. + * + * @param int $preview_mode + * DRUPAL_DISABLED, DRUPAL_OPTIONAL or DRUPAL_REQUIRED. + */ + public function setPreviewMode($preview_mode); } diff --git a/core/modules/node/src/Tests/NodeCreationTest.php b/core/modules/node/src/Tests/NodeCreationTest.php index 53b32b2..a895610 100644 --- a/core/modules/node/src/Tests/NodeCreationTest.php +++ b/core/modules/node/src/Tests/NodeCreationTest.php @@ -63,7 +63,7 @@ function testNodeCreation() { // 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->setDisplaySubmitted(TRUE); $node_type->save(); $this->drupalGet('node/' . $node->id()); diff --git a/core/modules/node/src/Tests/NodePostSettingsTest.php b/core/modules/node/src/Tests/NodePostSettingsTest.php index 35c3125..0acee50 100644 --- a/core/modules/node/src/Tests/NodePostSettingsTest.php +++ b/core/modules/node/src/Tests/NodePostSettingsTest.php @@ -29,7 +29,7 @@ function testPagePostInfo() { // Set "Basic page" content type to display post information. $edit = array(); - $edit['settings[node][submitted]'] = TRUE; + $edit['display_submitted'] = TRUE; $this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type')); // Create a node. @@ -46,7 +46,7 @@ function testPagePostInfo() { // Set "Basic page" content type to display post information. $edit = array(); - $edit['settings[node][submitted]'] = FALSE; + $edit['display_submitted'] = FALSE; $this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type')); // Create a node. diff --git a/core/modules/node/src/Tests/NodeRevisionsUiTest.php b/core/modules/node/src/Tests/NodeRevisionsUiTest.php index f2bc337..c9a4a36 100644 --- a/core/modules/node/src/Tests/NodeRevisionsUiTest.php +++ b/core/modules/node/src/Tests/NodeRevisionsUiTest.php @@ -39,7 +39,7 @@ function testNodeFormSaveWithoutRevision() { // Set page revision setting 'create new revision'. This will mean new // revisions are created by default when the node is edited. $type = entity_load('node_type', 'page'); - $type->settings['node']['options']['revision'] = TRUE; + $type->setNewRevision(TRUE); $type->save(); // Create the node. diff --git a/core/modules/node/src/Tests/NodeTestBase.php b/core/modules/node/src/Tests/NodeTestBase.php index cc0f8f8..764d0a8 100644 --- a/core/modules/node/src/Tests/NodeTestBase.php +++ b/core/modules/node/src/Tests/NodeTestBase.php @@ -34,13 +34,11 @@ protected function setUp() { // Create Basic page and Article node types. if ($this->profile != 'standard') { - $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page', 'settings' => array( - // Set proper default options for the page content type. - 'node' => array( - 'options' => array('promote' => FALSE), - 'submitted' => FALSE, - ), - ))); + $this->drupalCreateContentType(array( + 'type' => 'page', + 'name' => 'Basic page', + 'display_submitted' => FALSE, + )); $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); } $this->accessHandler = \Drupal::entityManager()->getAccessControlHandler('node'); diff --git a/core/modules/node/src/Tests/PagePreviewTest.php b/core/modules/node/src/Tests/PagePreviewTest.php index 708fc1a..071602f 100644 --- a/core/modules/node/src/Tests/PagePreviewTest.php +++ b/core/modules/node/src/Tests/PagePreviewTest.php @@ -8,6 +8,7 @@ namespace Drupal\node\Tests; use Drupal\Core\Language\LanguageInterface; +use Drupal\node\Entity\NodeType; /** * Tests the node entity preview functionality. @@ -202,7 +203,9 @@ function testPagePreviewWithRevisions() { $body_key = 'body[0][value]'; $term_key = $this->field_name; // Force revision on "Basic page" content. - $this->container->get('config.factory')->get('node.type.page')->set('settings.node.options', array('status', 'revision'))->save(); + $node_type = NodeType::load('page'); + $node_type->setNewRevision(TRUE); + $node_type->save(); // Fill in node creation form and preview node. $edit = array(); diff --git a/core/modules/node/src/Tests/Views/NodeContextualLinksTest.php b/core/modules/node/src/Tests/Views/NodeContextualLinksTest.php index c77df9c..bb01895 100644 --- a/core/modules/node/src/Tests/Views/NodeContextualLinksTest.php +++ b/core/modules/node/src/Tests/Views/NodeContextualLinksTest.php @@ -35,6 +35,7 @@ class NodeContextualLinksTest extends NodeTestBase { * Tests contextual links. */ public function testNodeContextualLinks() { + $this->drupalCreateContentType(array('type' => 'page')); $this->drupalCreateNode(array('promote' => 1)); $this->drupalGet('node'); diff --git a/core/modules/node/tests/modules/node_test_config/config/install/node.type.default.yml b/core/modules/node/tests/modules/node_test_config/config/install/node.type.default.yml index 2003aad..33d62b3 100644 --- a/core/modules/node/tests/modules/node_test_config/config/install/node.type.default.yml +++ b/core/modules/node/tests/modules/node_test_config/config/install/node.type.default.yml @@ -2,11 +2,8 @@ type: default name: Default description: 'Default description.' help: '' -settings: - node: - preview: 1 - options: - revision: false - submitted: true +new_revision: false +display_submitted: true +preview_mode: 1 status: true langcode: en diff --git a/core/modules/node/tests/modules/node_test_config/staging/node.type.import.yml b/core/modules/node/tests/modules/node_test_config/staging/node.type.import.yml index 9bab192..f1bafe4 100644 --- a/core/modules/node/tests/modules/node_test_config/staging/node.type.import.yml +++ b/core/modules/node/tests/modules/node_test_config/staging/node.type.import.yml @@ -2,11 +2,8 @@ type: import name: Import description: 'Import description.' help: '' -settings: - node: - preview: 1 - options: - revision: false - submitted: true +new_revision: false +display_submitted: true +preview_mode: 1 status: true langcode: en diff --git a/core/modules/quickedit/src/Form/QuickEditFieldForm.php b/core/modules/quickedit/src/Form/QuickEditFieldForm.php index a5c4b38..d4fc95e 100644 --- a/core/modules/quickedit/src/Form/QuickEditFieldForm.php +++ b/core/modules/quickedit/src/Form/QuickEditFieldForm.php @@ -121,9 +121,8 @@ protected function init(FormStateInterface $form_state, EntityInterface $entity, // @todo Rather than special-casing $node->revision, invoke prepareEdit() // once http://drupal.org/node/1863258 lands. if ($entity->getEntityTypeId() == 'node') { - $node_type_settings = $this->nodeTypeStorage->load($entity->bundle())->getModuleSettings('node'); - $options = (isset($node_type_settings['options'])) ? $node_type_settings['options'] : array(); - $entity->setNewRevision(!empty($options['revision'])); + $node_type = $this->nodeTypeStorage->load($entity->bundle()); + $entity->setNewRevision($node_type->isNewRevision()); $entity->revision_log = NULL; } diff --git a/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php b/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php index 1f39842..6a084f6 100644 --- a/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php +++ b/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php @@ -242,7 +242,7 @@ public function testUserWithPermission() { // in TempStore) and then save the entity. Now there should be two // revisions. $node_type = entity_load('node_type', 'article'); - $node_type->settings['node']['options']['revision'] = TRUE; + $node_type->setNewRevision(TRUE); $node_type->save(); // Retrieve field form. diff --git a/core/modules/rdf/src/Tests/StandardProfileTest.php b/core/modules/rdf/src/Tests/StandardProfileTest.php index 2b297a4..d097a5e 100644 --- a/core/modules/rdf/src/Tests/StandardProfileTest.php +++ b/core/modules/rdf/src/Tests/StandardProfileTest.php @@ -273,7 +273,7 @@ protected function doPageRdfaTests() { // true for testing. // @todo Clean-up standard profile defaults. $node_type = entity_load('node_type', 'page'); - $node_type->settings['node']['submitted'] = TRUE; + $node_type->setDisplaySubmitted(TRUE); $node_type->save(); // Feed the HTML into the parser. diff --git a/core/modules/rdf/src/Tests/UserAttributesTest.php b/core/modules/rdf/src/Tests/UserAttributesTest.php index 64c306b..840701a 100644 --- a/core/modules/rdf/src/Tests/UserAttributesTest.php +++ b/core/modules/rdf/src/Tests/UserAttributesTest.php @@ -55,6 +55,8 @@ function testUserAttributesInMarkup() { $this->drupalLogin($user1); + $this->drupalCreateContentType(array('type' => 'article')); + foreach($authors as $author) { $account_uri = url('user/' . $author->id(), array('absolute' => TRUE)); diff --git a/core/modules/statistics/src/Tests/Views/IntegrationTest.php b/core/modules/statistics/src/Tests/Views/IntegrationTest.php index 5ef8610..b26745a 100644 --- a/core/modules/statistics/src/Tests/Views/IntegrationTest.php +++ b/core/modules/statistics/src/Tests/Views/IntegrationTest.php @@ -55,6 +55,7 @@ protected function setUp() { // Create a new user for viewing nodes. $this->webUser = $this->drupalCreateUser(array('access content')); + $this->drupalCreateContentType(array('type' => 'page')); $this->node = $this->drupalCreateNode(array('type' => 'page')); // Enable access logging. diff --git a/core/modules/system/src/Tests/Menu/BreadcrumbTest.php b/core/modules/system/src/Tests/Menu/BreadcrumbTest.php index 6580e57..ea55662 100644 --- a/core/modules/system/src/Tests/Menu/BreadcrumbTest.php +++ b/core/modules/system/src/Tests/Menu/BreadcrumbTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\Component\Utility\Unicode; +use Drupal\node\Entity\NodeType; /** * Tests breadcrumbs functionality. @@ -158,10 +159,10 @@ function testBreadCrumbs() { // breadcrumbs may differ, possibly due to theme overrides. $menus = array('main', 'tools'); // Alter node type menu settings. - \Drupal::config("menu.entity.node.$type") - ->set('available_menus', $menus) - ->set('parent', 'tools:') - ->save(); + $node_type = NodeType::load($type); + $node_type->setThirdPartySetting('menu_ui', 'available_menus', $menus); + $node_type->setThirdPartySetting('menu_ui', 'parent', 'tools:'); + $node_type->save(); foreach ($menus as $menu) { // Create a parent node in the current menu. diff --git a/core/modules/system/src/Tests/System/DateTimeTest.php b/core/modules/system/src/Tests/System/DateTimeTest.php index a14d002..416a147 100644 --- a/core/modules/system/src/Tests/System/DateTimeTest.php +++ b/core/modules/system/src/Tests/System/DateTimeTest.php @@ -48,6 +48,7 @@ function testTimeZoneHandling() { // Create some nodes with different authored-on dates. $date1 = '2007-01-31 21:00:00 -1000'; $date2 = '2007-07-31 21:00:00 -1000'; + $this->drupalCreateContentType(array('type' => 'article')); $node1 = $this->drupalCreateNode(array('created' => strtotime($date1), 'type' => 'article')); $node2 = $this->drupalCreateNode(array('created' => strtotime($date2), 'type' => 'article')); diff --git a/core/modules/system/src/Tests/System/FrontPageTest.php b/core/modules/system/src/Tests/System/FrontPageTest.php index aeb758c..dd24ef5 100644 --- a/core/modules/system/src/Tests/System/FrontPageTest.php +++ b/core/modules/system/src/Tests/System/FrontPageTest.php @@ -29,6 +29,7 @@ protected function setUp() { // Create admin user, log in admin user, and create one node. $this->admin_user = $this->drupalCreateUser(array('access content', 'administer site configuration')); $this->drupalLogin($this->admin_user); + $this->drupalCreateContentType(array('type' => 'page')); $this->node_path = "node/" . $this->drupalCreateNode(array('promote' => 1))->id(); // Configure 'node' as front page. diff --git a/core/modules/system/src/Tests/Theme/TwigDebugMarkupTest.php b/core/modules/system/src/Tests/Theme/TwigDebugMarkupTest.php index efb0818..102f542 100644 --- a/core/modules/system/src/Tests/Theme/TwigDebugMarkupTest.php +++ b/core/modules/system/src/Tests/Theme/TwigDebugMarkupTest.php @@ -30,6 +30,7 @@ function testTwigDebugMarkup() { $extension = twig_extension(); theme_enable(array('test_theme')); \Drupal::config('system.theme')->set('default', 'test_theme')->save(); + $this->drupalCreateContentType(array('type' => 'page')); // Enable debug, rebuild the service container, and clear all caches. $parameters = $this->container->getParameter('twig.config'); $parameters['debug'] = TRUE; diff --git a/core/modules/user/src/Tests/UserTimeZoneTest.php b/core/modules/user/src/Tests/UserTimeZoneTest.php index f3ea297..4c09de0 100644 --- a/core/modules/user/src/Tests/UserTimeZoneTest.php +++ b/core/modules/user/src/Tests/UserTimeZoneTest.php @@ -46,6 +46,7 @@ function testUserTimeZone() { $date2 = '2007-03-11 01:00:00 -0800'; // One date in PDT (summer time): $date3 = '2007-03-20 21:00:00 -0700'; + $this->drupalCreateContentType(array('type' => 'article')); $node1 = $this->drupalCreateNode(array('created' => strtotime($date1), 'type' => 'article')); $node2 = $this->drupalCreateNode(array('created' => strtotime($date2), 'type' => 'article')); $node3 = $this->drupalCreateNode(array('created' => strtotime($date3), 'type' => 'article')); diff --git a/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php b/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php index c0f3a05..7dbc987 100644 --- a/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php +++ b/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php @@ -8,6 +8,7 @@ namespace Drupal\views\Tests\Entity; use Drupal\Core\Language\Language; +use Drupal\node\Entity\NodeType; use Drupal\views\Tests\ViewUnitTestBase; use Drupal\views\Views; @@ -63,9 +64,9 @@ protected function setUp() { } // Make sure we do not try to render non-existing user data. - $config = \Drupal::config('node.type.test'); - $config->set('settings.node.submitted', FALSE); - $config->save(); + $node_type = NodeType::create(array('type' => 'test')); + $node_type->setDisplaySubmitted(FALSE); + $node_type->save(); } /** diff --git a/core/modules/views/src/Tests/Plugin/MiniPagerTest.php b/core/modules/views/src/Tests/Plugin/MiniPagerTest.php index f8263a0..f6f31c4 100644 --- a/core/modules/views/src/Tests/Plugin/MiniPagerTest.php +++ b/core/modules/views/src/Tests/Plugin/MiniPagerTest.php @@ -41,6 +41,7 @@ class MiniPagerTest extends PluginTestBase { protected function setUp() { parent::setUp(); + $this->drupalCreateContentType(array('type' => 'page')); // Create a bunch of test nodes. for ($i = 0; $i < 20; $i++) { $this->nodes[] = $this->drupalCreateNode(); diff --git a/core/modules/views/src/Tests/Plugin/PagerTest.php b/core/modules/views/src/Tests/Plugin/PagerTest.php index 7a14e54..20e0718 100644 --- a/core/modules/views/src/Tests/Plugin/PagerTest.php +++ b/core/modules/views/src/Tests/Plugin/PagerTest.php @@ -111,6 +111,7 @@ public function testStorePagerSettings() { public function testNoLimit() { // Create 11 nodes and make sure that everyone is returned. // We create 11 nodes, because the default pager plugin had 10 items per page. + $this->drupalCreateContentType(array('type' => 'page')); for ($i = 0; $i < 11; $i++) { $this->drupalCreateNode(); } @@ -139,6 +140,7 @@ public function testNoLimit() { } public function testViewTotalRowsWithoutPager() { + $this->drupalCreateContentType(array('type' => 'page')); for ($i = 0; $i < 23; $i++) { $this->drupalCreateNode(); } @@ -156,6 +158,7 @@ public function testViewTotalRowsWithoutPager() { public function testLimit() { // Create 11 nodes and make sure that everyone is returned. // We create 11 nodes, because the default pager plugin had 10 items per page. + $this->drupalCreateContentType(array('type' => 'page')); for ($i = 0; $i < 11; $i++) { $this->drupalCreateNode(); } @@ -189,6 +192,7 @@ public function testLimit() { public function testNormalPager() { // Create 11 nodes and make sure that everyone is returned. // We create 11 nodes, because the default pager plugin had 10 items per page. + $this->drupalCreateContentType(array('type' => 'page')); for ($i = 0; $i < 11; $i++) { $this->drupalCreateNode(); } @@ -243,6 +247,7 @@ public function testNormalPager() { public function testRenderNullPager() { // Create 11 nodes and make sure that everyone is returned. // We create 11 nodes, because the default pager plugin had 10 items per page. + $this->drupalCreateContentType(array('type' => 'page')); for ($i = 0; $i < 11; $i++) { $this->drupalCreateNode(); } diff --git a/core/modules/views/src/Tests/Wizard/SortingTest.php b/core/modules/views/src/Tests/Wizard/SortingTest.php index b5d236a..eb6cc98 100644 --- a/core/modules/views/src/Tests/Wizard/SortingTest.php +++ b/core/modules/views/src/Tests/Wizard/SortingTest.php @@ -20,6 +20,7 @@ class SortingTest extends WizardTestBase { function testSorting() { // Create nodes, each with a different creation time so that we can do a // meaningful sort. + $this->drupalCreateContentType(array('type' => 'page')); $node1 = $this->drupalCreateNode(array('created' => REQUEST_TIME)); $node2 = $this->drupalCreateNode(array('created' => REQUEST_TIME + 1)); $node3 = $this->drupalCreateNode(array('created' => REQUEST_TIME + 2)); diff --git a/core/modules/views_ui/src/Tests/OverrideDisplaysTest.php b/core/modules/views_ui/src/Tests/OverrideDisplaysTest.php index 3b2ecf7..a3d4396 100644 --- a/core/modules/views_ui/src/Tests/OverrideDisplaysTest.php +++ b/core/modules/views_ui/src/Tests/OverrideDisplaysTest.php @@ -40,6 +40,7 @@ function testOverrideDisplays() { // Add a node that will appear in the view, so that the block will actually // be displayed. + $this->drupalCreateContentType(array('type' => 'page')); $this->drupalCreateNode(); // Make sure the title appears in the page. @@ -92,6 +93,7 @@ function testWizardMixedDefaultOverriddenDisplays() { // Add a node that will appear in the view, so that the block will actually // be displayed. + $this->drupalCreateContentType(array('type' => 'page')); $this->drupalCreateNode(); // Make sure that the feed, page and block all start off with the correct diff --git a/core/modules/views_ui/src/Tests/PreviewTest.php b/core/modules/views_ui/src/Tests/PreviewTest.php index f133354..c681ec4 100644 --- a/core/modules/views_ui/src/Tests/PreviewTest.php +++ b/core/modules/views_ui/src/Tests/PreviewTest.php @@ -98,6 +98,7 @@ function testPreviewUI() { public function testPreviewWithPagersUI() { // Create 11 nodes and make sure that everyone is returned. + $this->drupalCreateContentType(array('type' => 'page')); for ($i = 0; $i < 11; $i++) { $this->drupalCreateNode(); } diff --git a/core/profiles/standard/config/install/node.type.article.yml b/core/profiles/standard/config/install/node.type.article.yml index 6f4f302..7cb127d 100644 --- a/core/profiles/standard/config/install/node.type.article.yml +++ b/core/profiles/standard/config/install/node.type.article.yml @@ -2,11 +2,8 @@ type: article name: Article description: 'Use articles for time-sensitive content like news, press releases or blog posts.' help: '' -settings: - node: - preview: 1 - options: - revision: false - submitted: true +new_revision: false +preview_mode: 1 +display_submitted: true status: true langcode: en diff --git a/core/profiles/standard/config/install/node.type.page.yml b/core/profiles/standard/config/install/node.type.page.yml index 61ae323..f9b4353 100644 --- a/core/profiles/standard/config/install/node.type.page.yml +++ b/core/profiles/standard/config/install/node.type.page.yml @@ -2,11 +2,8 @@ type: page name: 'Basic page' description: 'Use basic pages for your static content, such as an ''About us'' page.' help: '' -settings: - node: - preview: 1 - options: - revision: false - submitted: false +new_revision: false +preview_mode: 1 +display_submitted: false status: true langcode: en