diff --git a/core/modules/node/node.module b/core/modules/node/node.module index fa6af54..15c1416 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -638,6 +638,9 @@ function template_preprocess_node(&$variables) { )); $variables['label'] = $variables['elements']['title']; unset($variables['elements']['title']); + // The variable page is set to TRUE in two occasions: + // - The view mode is 'full' and we are on /node/{nid} path. + // - The node is in preview and view mode is either 'full' or 'default'. $variables['page'] = ($variables['view_mode'] == 'full' && (node_is_page($node)) || (isset($node->in_preview) && in_array($node->preview_view_mode, array('full', 'default')))); // Helpful $content variable for templates. @@ -1129,7 +1132,7 @@ function node_page_build(&$page) { // Add 'Back to content edit editing' link on preview page. $attributes = \Drupal::request()->attributes; if ($attributes->get(RouteObjectInterface::ROUTE_NAME) == 'node.preview') { - $page['page_top']['node-preview'] = array( + $page['page_top']['node_preview'] = array( '#type' => 'container', '#attributes' => array( 'class' => array('node-preview-container', 'container-inline') @@ -1137,7 +1140,7 @@ function node_page_build(&$page) { ); $form = \Drupal::formBuilder()->getForm('\Drupal\node\Form\NodePreviewForm', $attributes->get('node_preview')); - $page['page_top']['node-preview']['view-mode'] = $form; + $page['page_top']['node_preview']['view_mode'] = $form; } } diff --git a/core/modules/node/node.routing.yml b/core/modules/node/node.routing.yml index bdfbf9f..5502d5c 100644 --- a/core/modules/node/node.routing.yml +++ b/core/modules/node/node.routing.yml @@ -48,7 +48,6 @@ node.preview: parameters: node_preview: type: 'node_preview' - #_entity_access: 'node.view' node.view: path: '/node/{node}' diff --git a/core/modules/node/node.services.yml b/core/modules/node/node.services.yml index 37e1e74..b25c0ed 100644 --- a/core/modules/node/node.services.yml +++ b/core/modules/node/node.services.yml @@ -27,7 +27,7 @@ services: tags: - { name: event_subscriber } node_preview: - class: Drupal\node\ParamConverter\NodepreviewConverter + class: Drupal\node\ParamConverter\NodePreviewConverter arguments: ['@user.tempstore'] tags: - { name: paramconverter } diff --git a/core/modules/node/src/Access/NodePreviewAccessCheck.php b/core/modules/node/src/Access/NodePreviewAccessCheck.php index cf23cb7..49aaa2b 100644 --- a/core/modules/node/src/Access/NodePreviewAccessCheck.php +++ b/core/modules/node/src/Access/NodePreviewAccessCheck.php @@ -35,7 +35,7 @@ public function __construct(EntityManagerInterface $entity_manager) { } /** - * Checks access to the node preview page for the node type. + * Checks access to the node preview page. * * @param \Drupal\Core\Session\AccountInterface $account * The currently logged in account. @@ -46,8 +46,13 @@ public function __construct(EntityManagerInterface $entity_manager) { * A \Drupal\Core\Access\AccessInterface constant value. */ public function access(AccountInterface $account, NodeInterface $node_preview) { - // TODO - return static::ALLOW; + if ($node_preview->isNew()) { + $access_controller = $this->entityManager->getAccessController('node'); + return $access_controller->createAccess($node_preview->bundle(), $account) ? static::ALLOW : static::DENY; + } + else { + return $node_preview->access('update', $account) ? static::ALLOW : static::DENY; + } } } diff --git a/core/modules/node/src/Controller/NodePreviewController.php b/core/modules/node/src/Controller/NodePreviewController.php index 276b05b..71acc53 100644 --- a/core/modules/node/src/Controller/NodePreviewController.php +++ b/core/modules/node/src/Controller/NodePreviewController.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\node\Controller\NodeViewController. + * Contains \Drupal\node\Controller\NodePreviewController. */ namespace Drupal\node\Controller; @@ -20,6 +20,8 @@ class NodePreviewController extends EntityViewController { * {@inheritdoc} */ public function view(EntityInterface $node_preview, $view_mode_id = 'full', $langcode = NULL) { + // Do not cache this page. + drupal_page_is_cacheable(FALSE); $node_preview->preview_view_mode = $view_mode_id; $build = array('nodes' => parent::view($node_preview, $view_mode_id)); diff --git a/core/modules/node/src/Form/NodePreviewForm.php b/core/modules/node/src/Form/NodePreviewForm.php index 13d14cf..142edf6 100644 --- a/core/modules/node/src/Form/NodePreviewForm.php +++ b/core/modules/node/src/Form/NodePreviewForm.php @@ -6,6 +6,7 @@ */ namespace Drupal\node\Form; + use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; @@ -65,11 +66,11 @@ public function getFormId() { public function buildForm(array $form, array &$form_state, EntityInterface $node = NULL) { $view_mode = $node->preview_view_mode; - $query_options = !$node->id() ? array('query' => array('uuid' => $node->uuid())) : array(); + $query_options = $node->isNew() ? array('query' => array('uuid' => $node->uuid())) : array(); $form['backlink'] = array( '#type' => 'link', '#title' => t('Back to content editing'), - '#href' => $node->id() ? 'node/' . $node->id() . '/edit' : 'node/add/' . $node->bundle(), + '#href' => $node->isNew() ? 'node/add/' . $node->bundle() : 'node/' . $node->id() . '/edit', '#options' => array('attributes' => array('class' => array('node-preview-backlink button-action'))) + $query_options, ); diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php index e61d83d..7688523 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -393,10 +393,6 @@ public function submit(array $form, array &$form_state) { $function($node, $form, $form_state); } - // Remove - $store = $this->tempStoreFactory->get('node_preview'); - $store->delete($node->uuid()); - return $node; } @@ -412,7 +408,13 @@ public function preview(array $form, array &$form_state) { $store = $this->tempStoreFactory->get('node_preview'); $this->entity->in_preview = TRUE; $store->set($this->entity->uuid(), $form_state); - $form_state['redirect'] = 'node/preview/' . $this->entity->uuid() . '/default'; + $form_state['redirect_route'] = array( + 'route_name' => 'node.preview', + 'route_parameters' => array( + 'node_preview' => $this->entity->uuid(), + 'view_mode_id' => 'default', + ), + ); } /** diff --git a/core/modules/node/src/ParamConverter/NodePreviewConverter.php b/core/modules/node/src/ParamConverter/NodePreviewConverter.php new file mode 100644 index 0000000..1b0f118 --- /dev/null +++ b/core/modules/node/src/ParamConverter/NodePreviewConverter.php @@ -0,0 +1,58 @@ +tempStoreFactory = $temp_store_factory; + } + + /** + * {@inheritdoc} + */ + public function convert($value, $definition, $name, array $defaults, Request $request) { + $store = $this->tempStoreFactory->get('node_preview'); + if ($form_state = $store->get($value)) { + return $form_state['controller']->getEntity(); + } + } + + /** + * {@inheritdoc} + */ + public function applies($definition, $name, Route $route) { + if (!empty($definition['type']) && $definition['type'] == 'node_preview') { + return TRUE; + } + return FALSE; + } + +} diff --git a/core/modules/node/src/ParamConverter/NodepreviewConverter.php b/core/modules/node/src/ParamConverter/NodepreviewConverter.php deleted file mode 100644 index 6c838b3..0000000 --- a/core/modules/node/src/ParamConverter/NodepreviewConverter.php +++ /dev/null @@ -1,58 +0,0 @@ -tempStoreFactory = $temp_store_factory; - } - - /** - * {@inheritdoc} - */ - public function convert($value, $definition, $name, array $defaults, Request $request) { - $store = $this->tempStoreFactory->get('node_preview'); - if ($form_state = $store->get($value)) { - return $form_state['controller']->getEntity(); - } - } - - /** - * {@inheritdoc} - */ - public function applies($definition, $name, Route $route) { - if (!empty($definition['type']) && $definition['type'] == 'node_preview') { - return TRUE; - } - return FALSE; - } - -}