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;
*/
protected $tempStoreFactory;
+ /**
+ * The Current User object.
+ *
+ * @var \Drupal\Core\Session\AccountInterface
+ */
+ protected $currentUser;
+
/**
* Constructs a NodeForm object.
*
* 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;
}
/**
$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')
);
}
$node = $this->entity;
if ($this->operation == 'edit') {
- $form['#title'] = $this->t('<em>Edit @type</em> @title', ['@type' => node_get_type_label($node), '@title' => $node->label()]);
+ $form['#title'] = $this->t('<em>Edit @type</em> @title', [
+ '@type' => node_get_type_label($node),
+ '@title' => $node->label()
+ ]);
}
// Changed must be sent to the client, for later overwrite error checking.
$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,
+ '#attributes' => [
+ 'class' => ['node-form-footer']
+ ]
+ ];
+ $form['status']['#group'] = 'footer';
+
// Node author information for administrators.
$form['author'] = [
'#type' => 'details',
$form['#attached']['library'][] = 'node/form';
- $form['#entity_builders']['update_status'] = '::updateStatus';
-
return $form;
}
* The current state of the form.
*
* @see \Drupal\node\NodeForm::form()
+ *
+ * @deprecated in Drupal 8.4.x, will be removed before Drupal 9.0.0.
+ * The "Publish" button was removed.
*/
public function updateStatus($entity_type_id, NodeInterface $node, array $form, FormStateInterface $form_state) {
$element = $form_state->getTriggeringElement();
$element['submit']['#access'] = $preview_mode != DRUPAL_REQUIRED || $form_state->get('has_been_previewed');
- // If saving is an option, privileged users get dedicated form submit
- // buttons to adjust the publishing status while saving in one go.
- // @todo This adjustment makes it close to impossible for contributed
- // modules to integrate with "the Save operation" of this form. Modules
- // need a way to plug themselves into 1) the ::submit() step, and
- // 2) the ::save() step, both decoupled from the pressed form button.
- if ($element['submit']['#access'] && \Drupal::currentUser()->hasPermission('administer nodes')) {
- // isNew | prev status » default & publish label & unpublish label
- // 1 | 1 » publish & Save and publish & Save as unpublished
- // 1 | 0 » unpublish & Save and publish & Save as unpublished
- // 0 | 1 » publish & Save and keep published & Save and unpublish
- // 0 | 0 » unpublish & Save and keep unpublished & Save and publish
-
- // Add a "Publish" button.
- $element['publish'] = $element['submit'];
- // If the "Publish" button is clicked, we want to update the status to "published".
- $element['publish']['#published_status'] = TRUE;
- $element['publish']['#dropbutton'] = 'save';
- if ($node->isNew()) {
- $element['publish']['#value'] = t('Save and publish');
- }
- else {
- $element['publish']['#value'] = $node->isPublished() ? t('Save and keep published') : t('Save and publish');
- }
- $element['publish']['#weight'] = 0;
-
- // Add a "Unpublish" button.
- $element['unpublish'] = $element['submit'];
- // If the "Unpublish" button is clicked, we want to update the status to "unpublished".
- $element['unpublish']['#published_status'] = FALSE;
- $element['unpublish']['#dropbutton'] = 'save';
- if ($node->isNew()) {
- $element['unpublish']['#value'] = t('Save as unpublished');
- }
- else {
- $element['unpublish']['#value'] = !$node->isPublished() ? t('Save and keep unpublished') : t('Save and unpublish');
- }
- $element['unpublish']['#weight'] = 10;
-
- // If already published, the 'publish' button is primary.
- if ($node->isPublished()) {
- unset($element['unpublish']['#button_type']);
- }
- // Otherwise, the 'unpublish' button is primary and should come first.
- else {
- unset($element['publish']['#button_type']);
- $element['unpublish']['#weight'] = -10;
- }
-
- // Remove the "Save" button.
- $element['submit']['#access'] = FALSE;
- }
-
$element['preview'] = [
'#type' => 'submit',
'#access' => $preview_mode != DRUPAL_DISABLED && ($node->access('create') || $node->access('update')),