summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-07-20 19:32:19 (GMT)
committerNathaniel Catchpole2017-07-20 19:32:19 (GMT)
commite0ea6c67e5b8438420dc55f11dac01eda0054259 (patch)
tree866a893b5dc971e04358c9b7ef7e975552a6d54b
parent687d4cff92607439d45e0a69fb9222812e920098 (diff)
Issue #2803875 by amateescu, timmillwood, mcdruid, shashikant_chauhan, sidharthap, Manuel Garcia, Berdir: Node form meta information should not come from a theme
-rw-r--r--core/modules/node/src/NodeForm.php44
-rw-r--r--core/modules/node/tests/src/Functional/NodeEditFormTest.php37
-rw-r--r--core/themes/seven/css/components/entity-meta.css2
-rw-r--r--core/themes/seven/seven.theme36
4 files changed, 87 insertions, 32 deletions
diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php
index 007b7c6..4c9bbac 100644
--- a/core/modules/node/src/NodeForm.php
+++ b/core/modules/node/src/NodeForm.php
@@ -7,6 +7,7 @@ use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Session\AccountInterface;
use Drupal\user\PrivateTempStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -23,6 +24,13 @@ class NodeForm extends ContentEntityForm {
protected $tempStoreFactory;
/**
+ * The Current User object.
+ *
+ * @var \Drupal\Core\Session\AccountInterface
+ */
+ protected $currentUser;
+
+ /**
* Constructs a NodeForm object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
@@ -33,10 +41,13 @@ class NodeForm extends ContentEntityForm {
* The entity type bundle service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
+ * @param \Drupal\Core\Session\AccountInterface $current_user
+ * The current user.
*/
- public function __construct(EntityManagerInterface $entity_manager, PrivateTempStoreFactory $temp_store_factory, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) {
+ public function __construct(EntityManagerInterface $entity_manager, PrivateTempStoreFactory $temp_store_factory, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL, AccountInterface $current_user) {
parent::__construct($entity_manager, $entity_type_bundle_info, $time);
$this->tempStoreFactory = $temp_store_factory;
+ $this->currentUser = $current_user;
}
/**
@@ -47,7 +58,8 @@ class NodeForm extends ContentEntityForm {
$container->get('entity.manager'),
$container->get('user.private_tempstore'),
$container->get('entity_type.bundle.info'),
- $container->get('datetime.time')
+ $container->get('datetime.time'),
+ $container->get('current_user')
);
}
@@ -102,6 +114,34 @@ class NodeForm extends ContentEntityForm {
$form['advanced']['#attributes']['class'][] = 'entity-meta';
+ $form['meta'] = [
+ '#type' => 'details',
+ '#group' => 'advanced',
+ '#weight' => -10,
+ '#title' => $this->t('Status'),
+ '#attributes' => ['class' => ['entity-meta__header']],
+ '#tree' => TRUE,
+ '#access' => $this->currentUser->hasPermission('administer nodes'),
+ ];
+ $form['meta']['published'] = [
+ '#type' => 'item',
+ '#markup' => $node->isPublished() ? $this->t('Published') : $this->t('Not published'),
+ '#access' => !$node->isNew(),
+ '#wrapper_attributes' => ['class' => ['entity-meta__title']],
+ ];
+ $form['meta']['changed'] = [
+ '#type' => 'item',
+ '#title' => $this->t('Last saved'),
+ '#markup' => !$node->isNew() ? format_date($node->getChangedTime(), 'short') : $this->t('Not saved yet'),
+ '#wrapper_attributes' => ['class' => ['entity-meta__last-saved']],
+ ];
+ $form['meta']['author'] = [
+ '#type' => 'item',
+ '#title' => $this->t('Author'),
+ '#markup' => $node->getOwner()->getUsername(),
+ '#wrapper_attributes' => ['class' => ['entity-meta__author']],
+ ];
+
$form['footer'] = [
'#type' => 'container',
'#weight' => 99,
diff --git a/core/modules/node/tests/src/Functional/NodeEditFormTest.php b/core/modules/node/tests/src/Functional/NodeEditFormTest.php
index ce032e5..c15ca70 100644
--- a/core/modules/node/tests/src/Functional/NodeEditFormTest.php
+++ b/core/modules/node/tests/src/Functional/NodeEditFormTest.php
@@ -200,6 +200,43 @@ class NodeEditFormTest extends NodeTestBase {
}
/**
+ * Tests the node meta information.
+ */
+ public function testNodeMetaInformation() {
+ // Check that regular users (i.e. without the 'administer nodes' permission)
+ // can not see the meta information.
+ $this->drupalLogin($this->webUser);
+ $this->drupalGet('node/add/page');
+ $this->assertNoText('Not saved yet');
+
+ // Create node to edit.
+ $edit['title[0][value]'] = $this->randomMachineName(8);
+ $edit['body[0][value]'] = $this->randomMachineName(16);
+ $this->drupalPostForm(NULL, $edit, t('Save'));
+
+ $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
+ $this->drupalGet("node/" . $node->id() . "/edit");
+ $this->assertNoText('Published');
+ $this->assertNoText(format_date($node->getChangedTime(), 'short'));
+
+ // Check that users with the 'administer nodes' permission can see the meta
+ // information.
+ $this->drupalLogin($this->adminUser);
+ $this->drupalGet('node/add/page');
+ $this->assertText('Not saved yet');
+
+ // Create node to edit.
+ $edit['title[0][value]'] = $this->randomMachineName(8);
+ $edit['body[0][value]'] = $this->randomMachineName(16);
+ $this->drupalPostForm(NULL, $edit, t('Save'));
+
+ $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
+ $this->drupalGet("node/" . $node->id() . "/edit");
+ $this->assertText('Published');
+ $this->assertText(format_date($node->getChangedTime(), 'short'));
+ }
+
+ /**
* Checks that the "authored by" works correctly with various values.
*
* @param \Drupal\node\NodeInterface $node
diff --git a/core/themes/seven/css/components/entity-meta.css b/core/themes/seven/css/components/entity-meta.css
index 701e8dc..f6999be 100644
--- a/core/themes/seven/css/components/entity-meta.css
+++ b/core/themes/seven/css/components/entity-meta.css
@@ -17,6 +17,8 @@
padding: 1em 1.5em;
}
.entity-meta__title {
+ font-size: 1.231em;
+ font-weight: bold;
text-shadow: 0 1px 0 #fff;
margin: 0.25em 0;
}
diff --git a/core/themes/seven/seven.theme b/core/themes/seven/seven.theme
index c6da809..1559d0c 100644
--- a/core/themes/seven/seven.theme
+++ b/core/themes/seven/seven.theme
@@ -147,42 +147,18 @@ function seven_preprocess_maintenance_page(&$variables) {
/**
* Implements hook_form_BASE_FORM_ID_alter() for \Drupal\node\NodeForm.
*
- * Changes vertical tabs to container and adds meta information.
+ * Changes vertical tabs to container.
*/
function seven_form_node_form_alter(&$form, FormStateInterface $form_state) {
- /** @var \Drupal\node\NodeInterface $node */
- $node = $form_state->getFormObject()->getEntity();
-
$form['#theme'] = ['node_edit_form'];
$form['#attached']['library'][] = 'seven/node-form';
$form['advanced']['#type'] = 'container';
- $is_new = !$node->isNew() ? format_date($node->getChangedTime(), 'short') : t('Not saved yet');
- $form['meta'] = [
- '#attributes' => ['class' => ['entity-meta__header']],
- '#type' => 'container',
- '#group' => 'advanced',
- '#weight' => -100,
- 'published' => [
- '#type' => 'html_tag',
- '#tag' => 'h3',
- '#value' => $node->isPublished() ? t('Published') : t('Not published'),
- '#access' => !$node->isNew(),
- '#attributes' => [
- 'class' => ['entity-meta__title'],
- ],
- ],
- 'changed' => [
- '#type' => 'item',
- '#wrapper_attributes' => ['class' => ['entity-meta__last-saved', 'container-inline']],
- '#markup' => '<h4 class="label inline">' . t('Last saved') . '</h4> ' . $is_new,
- ],
- 'author' => [
- '#type' => 'item',
- '#wrapper_attributes' => ['class' => ['author', 'container-inline']],
- '#markup' => '<h4 class="label inline">' . t('Author') . '</h4> ' . $node->getOwner()->getUsername(),
- ],
- ];
+ $form['meta']['#type'] = 'container';
+ $form['meta']['#access'] = TRUE;
+ $form['meta']['changed']['#wrapper_attributes']['class'][] = 'container-inline';
+ $form['meta']['author']['#wrapper_attributes']['class'][] = 'container-inline';
+
$form['revision_information']['#type'] = 'container';
$form['revision_information']['#group'] = 'meta';
}