Issue #2053461 by larowlan, andypost, tim.plunkett, swentel: Node type settings such as published state, promoted state, create revision and author information cannot be turned off.
parent
f8d09132da
commit
cc7b115ed8
|
@ -119,7 +119,7 @@ class EditFieldForm extends FormBase {
|
||||||
if ($entity->entityType() == 'node') {
|
if ($entity->entityType() == 'node') {
|
||||||
$node_type_settings = $this->nodeTypeStorage->load($entity->bundle())->getModuleSettings('node');
|
$node_type_settings = $this->nodeTypeStorage->load($entity->bundle())->getModuleSettings('node');
|
||||||
$options = (isset($node_type_settings['options'])) ? $node_type_settings['options'] : array();
|
$options = (isset($node_type_settings['options'])) ? $node_type_settings['options'] : array();
|
||||||
$entity->setNewRevision(in_array('revision', $options));
|
$entity->setNewRevision(!empty($options['revision']));
|
||||||
$entity->log = NULL;
|
$entity->log = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -245,7 +245,9 @@ class EditLoadingTest extends WebTestBase {
|
||||||
// then again retrieve the field form, fill it, submit it (so it ends up
|
// 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
|
// in TempStore) and then save the entity. Now there should be two
|
||||||
// revisions.
|
// revisions.
|
||||||
$this->container->get('config.factory')->get('node.type.article')->set('settings.node.options', array('status', 'revision'))->save();
|
$node_type = entity_load('node_type', 'article');
|
||||||
|
$node_type->settings['node']['options']['revision'] = TRUE;
|
||||||
|
$node_type->save();
|
||||||
|
|
||||||
// Retrieve field form.
|
// Retrieve field form.
|
||||||
$post = array('nocssjs' => 'true', 'reset' => 'true');
|
$post = array('nocssjs' => 'true', 'reset' => 'true');
|
||||||
|
|
|
@ -9,7 +9,7 @@ settings:
|
||||||
node:
|
node:
|
||||||
preview: 1
|
preview: 1
|
||||||
options:
|
options:
|
||||||
status: status
|
status: true
|
||||||
# Not promoted to front page.
|
# Not promoted to front page.
|
||||||
promote: false
|
promote: false
|
||||||
sticky: false
|
sticky: false
|
||||||
|
|
|
@ -61,16 +61,16 @@ node.settings.node:
|
||||||
label: 'Publishing options'
|
label: 'Publishing options'
|
||||||
mapping:
|
mapping:
|
||||||
status:
|
status:
|
||||||
type: string
|
type: boolean
|
||||||
label: 'Published'
|
label: 'Published'
|
||||||
promote:
|
promote:
|
||||||
type: string
|
type: boolean
|
||||||
label: 'Promoted to front page'
|
label: 'Promoted to front page'
|
||||||
sticky:
|
sticky:
|
||||||
type: string
|
type: boolean
|
||||||
label: 'Sticky at top of lists'
|
label: 'Sticky at top of lists'
|
||||||
revision:
|
revision:
|
||||||
type: string
|
type: boolean
|
||||||
label: 'Create new revision'
|
label: 'Create new revision'
|
||||||
submitted:
|
submitted:
|
||||||
type: boolean
|
type: boolean
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
namespace Drupal\node\Entity;
|
namespace Drupal\node\Entity;
|
||||||
|
|
||||||
|
use Drupal\Component\Utility\NestedArray;
|
||||||
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
||||||
use Drupal\Core\Entity\EntityStorageControllerInterface;
|
use Drupal\Core\Entity\EntityStorageControllerInterface;
|
||||||
use Drupal\node\NodeTypeInterface;
|
use Drupal\node\NodeTypeInterface;
|
||||||
|
@ -209,4 +210,26 @@ class NodeType extends ConfigEntityBase implements NodeTypeInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@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'] = NestedArray::mergeDeep(array(
|
||||||
|
'options' => array(
|
||||||
|
'status' => TRUE,
|
||||||
|
'promote' => TRUE,
|
||||||
|
'sticky' => FALSE,
|
||||||
|
'revision' => FALSE,
|
||||||
|
),
|
||||||
|
'preview' => DRUPAL_OPTIONAL,
|
||||||
|
'submitted' => TRUE,
|
||||||
|
), $values['settings']['node']);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ class NodeFormController extends ContentEntityFormController {
|
||||||
foreach (array('status', 'promote', 'sticky') as $key) {
|
foreach (array('status', 'promote', 'sticky') as $key) {
|
||||||
// Multistep node forms might have filled in something already.
|
// Multistep node forms might have filled in something already.
|
||||||
if ($node->$key->isEmpty()) {
|
if ($node->$key->isEmpty()) {
|
||||||
$node->$key = (int) in_array($key, $this->settings['options']);
|
$node->$key = (int) !empty($this->settings['options'][$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$node->setAuthorId(\Drupal::currentUser()->id());
|
$node->setAuthorId(\Drupal::currentUser()->id());
|
||||||
|
@ -56,7 +56,7 @@ class NodeFormController extends ContentEntityFormController {
|
||||||
$node->log = NULL;
|
$node->log = NULL;
|
||||||
}
|
}
|
||||||
// Always use the default revision setting.
|
// Always use the default revision setting.
|
||||||
$node->setNewRevision(in_array('revision', $this->settings['options']));
|
$node->setNewRevision(!empty($this->settings['options']['revision']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
namespace Drupal\node;
|
namespace Drupal\node;
|
||||||
|
|
||||||
use Drupal\Core\Entity\EntityFormController;
|
use Drupal\Core\Entity\EntityFormController;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Drupal\Component\Utility\MapArray;
|
||||||
use Drupal\Component\Utility\String;
|
use Drupal\Component\Utility\String;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,13 +31,8 @@ class NodeTypeFormController extends EntityFormController {
|
||||||
}
|
}
|
||||||
|
|
||||||
$node_settings = $type->getModuleSettings('node');
|
$node_settings = $type->getModuleSettings('node');
|
||||||
// Ensure default settings.
|
// Prepare node options to be used for 'checkboxes' form element.
|
||||||
$node_settings += array(
|
$node_settings['options'] = MapArray::copyValuesToKeys(array_keys(array_filter($node_settings['options'])));
|
||||||
'options' => array('status', 'promote'),
|
|
||||||
'preview' => DRUPAL_OPTIONAL,
|
|
||||||
'submitted' => TRUE,
|
|
||||||
);
|
|
||||||
|
|
||||||
$form['name'] = array(
|
$form['name'] = array(
|
||||||
'#title' => t('Name'),
|
'#title' => t('Name'),
|
||||||
'#type' => 'textfield',
|
'#type' => 'textfield',
|
||||||
|
|
|
@ -60,6 +60,19 @@ class NodeCreationTest extends NodeTestBase {
|
||||||
// Check that the node exists in the database.
|
// Check that the node exists in the database.
|
||||||
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
|
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
|
||||||
$this->assertTrue($node, 'Node found in database.');
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -61,6 +61,7 @@ class NodePostSettingsTest extends NodeTestBase {
|
||||||
$this->drupalPostForm('node/add/page', $edit, t('Save'));
|
$this->drupalPostForm('node/add/page', $edit, t('Save'));
|
||||||
|
|
||||||
// Check that the post information is displayed.
|
// Check that the post information is displayed.
|
||||||
$this->assertNoRaw('<span class="submitted">', 'Post information is not displayed.');
|
$elements = $this->xpath('//*[contains(@class,:class)]', array(':class' => 'submitted'));
|
||||||
|
$this->assertEqual(count($elements), 0, 'Post information is not displayed.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,13 @@ abstract class NodeTestBase extends WebTestBase {
|
||||||
|
|
||||||
// Create Basic page and Article node types.
|
// Create Basic page and Article node types.
|
||||||
if ($this->profile != 'standard') {
|
if ($this->profile != 'standard') {
|
||||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
|
$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' => 'article', 'name' => 'Article'));
|
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
|
||||||
}
|
}
|
||||||
$this->accessController = \Drupal::entityManager()->getAccessController('node');
|
$this->accessController = \Drupal::entityManager()->getAccessController('node');
|
||||||
|
|
|
@ -692,10 +692,11 @@ function template_preprocess_node(&$variables) {
|
||||||
field_attach_preprocess($node, $variables['content'], $variables);
|
field_attach_preprocess($node, $variables['content'], $variables);
|
||||||
|
|
||||||
// Display post information only on certain node types.
|
// Display post information only on certain node types.
|
||||||
// Avoid loading the entire node type config entity here.
|
// Avoid loading the entire node type config entity here that may not exist.
|
||||||
$submitted = \Drupal::config('node.type.' . $node->bundle())->get('settings.node.submitted') ?: TRUE;
|
$node_type_config = \Drupal::config('node.type.' . $node->bundle());
|
||||||
if ($submitted) {
|
// Display submitted by default.
|
||||||
$variables['display_submitted'] = TRUE;
|
$variables['display_submitted'] = $node_type_config->isNew() || $node_type_config->get('settings.node.submitted');
|
||||||
|
if ($variables['display_submitted']) {
|
||||||
$variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date']));
|
$variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date']));
|
||||||
if (theme_get_setting('features.node_user_picture')) {
|
if (theme_get_setting('features.node_user_picture')) {
|
||||||
// To change user picture settings (e.g. image style), edit the 'compact'
|
// To change user picture settings (e.g. image style), edit the 'compact'
|
||||||
|
@ -708,7 +709,6 @@ function template_preprocess_node(&$variables) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$variables['display_submitted'] = FALSE;
|
|
||||||
$variables['submitted'] = '';
|
$variables['submitted'] = '';
|
||||||
$variables['user_picture'] = '';
|
$variables['user_picture'] = '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -282,6 +282,13 @@ class StandardProfileTest extends WebTestBase {
|
||||||
* displayed in teaser view, so it is tested in the front page tests.
|
* displayed in teaser view, so it is tested in the front page tests.
|
||||||
*/
|
*/
|
||||||
protected function doPageRdfaTests() {
|
protected function doPageRdfaTests() {
|
||||||
|
// The standard profile hides the created date on pages. Revert display to
|
||||||
|
// true for testing.
|
||||||
|
// @todo Clean-up standard profile defaults.
|
||||||
|
$node_type = entity_load('node_type', 'page');
|
||||||
|
$node_type->settings['node']['submitted'] = TRUE;
|
||||||
|
$node_type->save();
|
||||||
|
|
||||||
// Feed the HTML into the parser.
|
// Feed the HTML into the parser.
|
||||||
$uri_info = $this->page->uri();
|
$uri_info = $this->page->uri();
|
||||||
$path = $uri_info['path'];
|
$path = $uri_info['path'];
|
||||||
|
|
|
@ -9,10 +9,10 @@ settings:
|
||||||
node:
|
node:
|
||||||
preview: '1'
|
preview: '1'
|
||||||
options:
|
options:
|
||||||
status: status
|
status: true
|
||||||
promote: promote
|
promote: true
|
||||||
sticky: '0'
|
sticky: false
|
||||||
revision: '0'
|
revision: false
|
||||||
submitted: '1'
|
submitted: true
|
||||||
status: '1'
|
status: '1'
|
||||||
langcode: en
|
langcode: en
|
||||||
|
|
|
@ -9,10 +9,10 @@ settings:
|
||||||
node:
|
node:
|
||||||
preview: '1'
|
preview: '1'
|
||||||
options:
|
options:
|
||||||
status: status
|
status: true
|
||||||
promote: '0'
|
promote: false
|
||||||
sticky: '0'
|
sticky: false
|
||||||
revision: '0'
|
revision: false
|
||||||
submitted: '0'
|
submitted: false
|
||||||
status: '1'
|
status: '1'
|
||||||
langcode: en
|
langcode: en
|
||||||
|
|
Loading…
Reference in New Issue