diff --git a/core/modules/node/node.services.yml b/core/modules/node/node.services.yml index eb48e7edaac6..2586da355cd7 100644 --- a/core/modules/node/node.services.yml +++ b/core/modules/node/node.services.yml @@ -10,10 +10,9 @@ services: - { name: backend_overridable } access_check.node.revision: class: Drupal\node\Access\NodeRevisionAccessCheck - arguments: ['@entity.manager', '@database'] + arguments: ['@entity.manager'] tags: - { name: access_check, applies_to: _access_node_revision } - - { name: backend_overridable } access_check.node.add: class: Drupal\node\Access\NodeAddAccessCheck arguments: ['@entity.manager'] diff --git a/core/modules/node/src/Access/NodeRevisionAccessCheck.php b/core/modules/node/src/Access/NodeRevisionAccessCheck.php index f7309d739777..abdf8c920010 100644 --- a/core/modules/node/src/Access/NodeRevisionAccessCheck.php +++ b/core/modules/node/src/Access/NodeRevisionAccessCheck.php @@ -8,7 +8,6 @@ namespace Drupal\node\Access; use Drupal\Core\Access\AccessResult; -use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Routing\Access\AccessInterface; use Drupal\Core\Session\AccountInterface; @@ -23,7 +22,7 @@ class NodeRevisionAccessCheck implements AccessInterface { /** * The node storage. * - * @var \Drupal\Core\Entity\EntityStorageInterface + * @var \Drupal\node\NodeStorageInterface */ protected $nodeStorage; @@ -34,13 +33,6 @@ class NodeRevisionAccessCheck implements AccessInterface { */ protected $nodeAccess; - /** - * The database connection. - * - * @var \Drupal\Core\Database\Connection - */ - protected $connection; - /** * A static cache of access checks. * @@ -56,10 +48,9 @@ class NodeRevisionAccessCheck implements AccessInterface { * @param \Drupal\Core\Database\Connection $connection * The database connection. */ - public function __construct(EntityManagerInterface $entity_manager, Connection $connection) { + public function __construct(EntityManagerInterface $entity_manager) { $this->nodeStorage = $entity_manager->getStorage('node'); $this->nodeAccess = $entity_manager->getAccessControlHandler('node'); - $this->connection = $connection; } /** @@ -147,7 +138,7 @@ class NodeRevisionAccessCheck implements AccessInterface { // different revisions so there is no need for a separate database check. // Also, if you try to revert to or delete the default revision, that's // not good. - if ($node->isDefaultRevision() && ($this->connection->query('SELECT COUNT(*) FROM {node_field_revision} WHERE nid = :nid AND default_langcode = 1', array(':nid' => $node->id()))->fetchField() == 1 || $op == 'update' || $op == 'delete')) { + if ($node->isDefaultRevision() && ($this->nodeStorage->countDefaultLanguageRevisions($node) == 1 || $op == 'update' || $op == 'delete')) { $this->access[$cid] = FALSE; } elseif ($account->hasPermission('administer nodes')) { diff --git a/core/modules/node/src/NodeStorage.php b/core/modules/node/src/NodeStorage.php index e3c90fbea169..830fc3265daa 100644 --- a/core/modules/node/src/NodeStorage.php +++ b/core/modules/node/src/NodeStorage.php @@ -39,6 +39,13 @@ class NodeStorage extends SqlContentEntityStorage implements NodeStorageInterfac )->fetchCol(); } + /** + * {@inheritdoc} + */ + public function countDefaultLanguageRevisions(NodeInterface $node) { + return $this->database->query('SELECT COUNT(*) FROM {node_field_revision} WHERE nid = :nid AND default_langcode = 1', array(':nid' => $node->id()))->fetchField(); + } + /** * {@inheritdoc} */ diff --git a/core/modules/node/src/NodeStorageInterface.php b/core/modules/node/src/NodeStorageInterface.php index 2b5e91f38ad0..1ca7fabdb07f 100644 --- a/core/modules/node/src/NodeStorageInterface.php +++ b/core/modules/node/src/NodeStorageInterface.php @@ -38,6 +38,17 @@ interface NodeStorageInterface extends EntityStorageInterface { */ public function userRevisionIds(AccountInterface $account); + /** + * Counts the number of revisions in the default language. + * + * @param \Drupal\node\NodeInterface + * The node entity. + * + * @return int + * The number of revisions in the default language. + */ + public function countDefaultLanguageRevisions(NodeInterface $node); + /** * Updates all nodes of one type to be of another type. *