diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php index 007b7c640b674963cc2919fb995f4042c3ed548b..4c9bbac7b6595506037068b9548201969dece0a2 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -7,6 +7,7 @@ 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; @@ -22,6 +23,13 @@ class NodeForm extends ContentEntityForm { */ protected $tempStoreFactory; + /** + * The Current User object. + * + * @var \Drupal\Core\Session\AccountInterface + */ + protected $currentUser; + /** * Constructs a NodeForm object. * @@ -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 @@ public static function create(ContainerInterface $container) { $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 @@ public function form(array $form, FormStateInterface $form_state) { $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 ce032e5909f482baddd67739dcf53fab79aa8377..c15ca70bbe3beeb27754b07997325a6dbc9ee52d 100644 --- a/core/modules/node/tests/src/Functional/NodeEditFormTest.php +++ b/core/modules/node/tests/src/Functional/NodeEditFormTest.php @@ -199,6 +199,43 @@ public function testNodeEditAuthoredBy() { $this->assertIdentical($this->webUser->id(), $node->getOwner()->id()); } + /** + * 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. * diff --git a/core/themes/seven/css/components/entity-meta.css b/core/themes/seven/css/components/entity-meta.css index 701e8dc9836dd8319474731e424228c8649590a4..f6999beabe465c82c4ea05fac3aac9df5ed3554c 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 c6da8098d74ad924d4a6561b20bbd0569d35f390..1559d0c03c2390b7951bfb78974b9b9a840d5850 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' => '

' . t('Last saved') . '

' . $is_new, - ], - 'author' => [ - '#type' => 'item', - '#wrapper_attributes' => ['class' => ['author', 'container-inline']], - '#markup' => '

' . t('Author') . '

' . $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'; }