Commit 8dbd209e authored by catch's avatar catch

Issue #2313095 by claudiu.cristea, l0ke, umarzaffer, mrjmd, dawehner,...

Issue #2313095 by claudiu.cristea, l0ke, umarzaffer, mrjmd, dawehner, alexpott, catch: Move node constants to NodeInterface
parent ed9c8e09
......@@ -6,6 +6,7 @@
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Session\AccountInterface;
use Drupal\node\NodeInterface;
/**
* Provides a couple of menu link tree manipulators.
......@@ -147,7 +148,7 @@ public function checkNodeAccess(array $tree) {
}
else {
$access_result->addCacheContexts(['user.node_grants:view']);
$query->condition('status', NODE_PUBLISHED);
$query->condition('status', NodeInterface::PUBLISHED);
}
$nids = $query->execute();
......
......@@ -7,6 +7,7 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\Entity\EntityStorageInterface;
......@@ -160,7 +161,7 @@ public function build() {
// not show unpublished books.
$nid = \Drupal::entityQuery('node')
->condition('nid', $node->book['bid'], '=')
->condition('status', NODE_PUBLISHED)
->condition('status', NodeInterface::PUBLISHED)
->execute();
// Only show the block if the user has view access for the top-level node.
......
......@@ -15,6 +15,7 @@
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\node\NodeInterface;
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
use Drupal\file\Entity\File;
use Drupal\node\Entity\Node;
......@@ -385,7 +386,7 @@ public function testAutocreateValidation() {
$node = Node::create([
'title' => $title,
'type' => 'node',
'status' => NODE_NOT_PUBLISHED,
'status' => NodeInterface::NOT_PUBLISHED,
]);
$entity = EntityTest::create([
......@@ -409,14 +410,14 @@ public function testAutocreateValidation() {
$unsaved_unpublished_node = Node::create([
'title' => $unsaved_unpublished_node_title,
'type' => 'node',
'status' => NODE_NOT_PUBLISHED,
'status' => NodeInterface::NOT_PUBLISHED,
]);
$saved_unpublished_node_title = $this->randomString();
$saved_unpublished_node = Node::create([
'title' => $saved_unpublished_node_title,
'type' => 'node',
'status' => NODE_NOT_PUBLISHED,
'status' => NodeInterface::NOT_PUBLISHED,
]);
$saved_unpublished_node->save();
......@@ -424,7 +425,7 @@ public function testAutocreateValidation() {
$saved_published_node = Node::create([
'title' => $saved_published_node_title,
'type' => 'node',
'status' => NODE_PUBLISHED,
'status' => NodeInterface::PUBLISHED,
]);
$saved_published_node->save();
......
......@@ -2,6 +2,7 @@
namespace Drupal\forum\Tests\Views;
use Drupal\node\NodeInterface;
use Drupal\views\Views;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
......@@ -48,7 +49,7 @@ public function testForumIntegration() {
// Create some nodes which are part of this forum with some comments.
$nodes = array();
for ($i = 0; $i < 3; $i++) {
$node = $this->drupalCreateNode(array('type' => 'forum', 'taxonomy_forums' => array($term->id()), 'sticky' => $i == 0 ? NODE_STICKY : NODE_NOT_STICKY));
$node = $this->drupalCreateNode(['type' => 'forum', 'taxonomy_forums' => [$term->id()], 'sticky' => $i == 0 ? NodeInterface::STICKY : NodeInterface::NOT_STICKY]);
$nodes[] = $node;
}
......@@ -70,17 +71,17 @@ public function testForumIntegration() {
$expected_result = array();
$expected_result[] = array(
'nid' => $nodes[0]->id(),
'sticky' => NODE_STICKY,
'sticky' => NodeInterface::STICKY,
'comment_count' => 1.
);
$expected_result[] = array(
'nid' => $nodes[1]->id(),
'sticky' => NODE_NOT_STICKY,
'sticky' => NodeInterface::NOT_STICKY,
'comment_count' => 2.
);
$expected_result[] = array(
'nid' => $nodes[2]->id(),
'sticky' => NODE_NOT_STICKY,
'sticky' => NodeInterface::NOT_STICKY,
'comment_count' => 3.
);
$column_map = array(
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\hal\Kernel;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Drupal\user\Entity\User;
use Drupal\node\Entity\NodeType;
......@@ -44,7 +45,7 @@ public function testNodeTranslation() {
'title' => $this->randomMachineName(),
'uid' => $user->id(),
'type' => $node_type->id(),
'status' => NODE_PUBLISHED,
'status' => NodeInterface::PUBLISHED,
'langcode' => 'en',
'promote' => 1,
'sticky' => 0,
......
......@@ -4,6 +4,7 @@
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Language\LanguageInterface;
use Drupal\node\NodeInterface;
/**
* Tests you can enable multilingual support on content types and configure a
......@@ -170,7 +171,7 @@ public function testContentTypeDirLang() {
$nodes[$langcode] = $this->drupalCreateNode(array(
'langcode' => $langcode,
'type' => $type->id(),
'promote' => NODE_PROMOTED,
'promote' => NodeInterface::PROMOTED,
));
}
......
......@@ -10,6 +10,7 @@
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\system\Entity\Menu;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
/**
* Add a custom menu, add menu links to the custom menu and Tools menu, check
......@@ -542,7 +543,7 @@ function testUnpublishedNodeMenuItem() {
// Create an unpublished node.
$node = $this->drupalCreateNode(array(
'type' => 'article',
'status' => NODE_NOT_PUBLISHED,
'status' => NodeInterface::NOT_PUBLISHED,
));
$item = $this->addMenuLink('', '/node/' . $node->id());
......
......@@ -31,31 +31,49 @@
/**
* Denotes that the node is not published.
*
* @deprecated Scheduled for removal in Drupal 9.0.x.
* Use \Drupal\node\NodeInterface::NOT_PUBLISHED instead.
*/
const NODE_NOT_PUBLISHED = 0;
/**
* Denotes that the node is published.
*
* @deprecated Scheduled for removal in Drupal 9.0.x.
* Use \Drupal\node\NodeInterface::PUBLISHED instead.
*/
const NODE_PUBLISHED = 1;
/**
* Denotes that the node is not promoted to the front page.
*
* @deprecated Scheduled for removal in Drupal 9.0.x.
* Use \Drupal\node\NodeInterface::NOT_PROMOTED instead.
*/
const NODE_NOT_PROMOTED = 0;
/**
* Denotes that the node is promoted to the front page.
*
* @deprecated Scheduled for removal in Drupal 9.0.x.
* Use \Drupal\node\NodeInterface::PROMOTED instead.
*/
const NODE_PROMOTED = 1;
/**
* Denotes that the node is not sticky at the top of the page.
*
* @deprecated Scheduled for removal in Drupal 9.0.x.
* Use \Drupal\node\NodeInterface::NOT_STICKY instead.
*/
const NODE_NOT_STICKY = 0;
/**
* Denotes that the node is sticky at the top of the page.
*
* @deprecated Scheduled for removal in Drupal 9.0.x.
* Use \Drupal\node\NodeInterface::STICKY instead.
*/
const NODE_STICKY = 1;
......@@ -742,15 +760,15 @@ function node_get_recent($number = 10) {
// have some unpublished nodes to view before adding the condition.
$access_query = \Drupal::entityQuery('node')
->condition('uid', $account->id())
->condition('status', NODE_NOT_PUBLISHED);
->condition('status', NodeInterface::NOT_PUBLISHED);
if ($account->hasPermission('view own unpublished content') && ($own_unpublished = $access_query->execute())) {
$query->orConditionGroup()
->condition('status', NODE_PUBLISHED)
->condition('status', NodeInterface::PUBLISHED)
->condition('nid', $own_unpublished, 'IN');
}
else {
// If not, restrict the query to published nodes.
$query->condition('status', NODE_PUBLISHED);
$query->condition('status', NodeInterface::PUBLISHED);
}
}
$nids = $query
......
......@@ -229,7 +229,7 @@ public function isPromoted() {
* {@inheritdoc}
*/
public function setPromoted($promoted) {
$this->set('promote', $promoted ? NODE_PROMOTED : NODE_NOT_PROMOTED);
$this->set('promote', $promoted ? NodeInterface::PROMOTED : NodeInterface::NOT_PROMOTED);
return $this;
}
......@@ -244,7 +244,7 @@ public function isSticky() {
* {@inheritdoc}
*/
public function setSticky($sticky) {
$this->set('sticky', $sticky ? NODE_STICKY : NODE_NOT_STICKY);
$this->set('sticky', $sticky ? NodeInterface::STICKY : NodeInterface::NOT_STICKY);
return $this;
}
......
......@@ -13,6 +13,36 @@
*/
interface NodeInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface, RevisionLogInterface, EntityPublishedInterface {
/**
* Denotes that the node is not published.
*/
const NOT_PUBLISHED = 0;
/**
* Denotes that the node is published.
*/
const PUBLISHED = 1;
/**
* Denotes that the node is not promoted to the front page.
*/
const NOT_PROMOTED = 0;
/**
* Denotes that the node is promoted to the front page.
*/
const PROMOTED = 1;
/**
* Denotes that the node is not sticky at the top of the page.
*/
const NOT_STICKY = 0;
/**
* Denotes that the node is sticky at the top of the page.
*/
const STICKY = 1;
/**
* Gets the node type.
*
......
......@@ -20,8 +20,7 @@ class PublishNode extends ActionBase {
* {@inheritdoc}
*/
public function execute($entity = NULL) {
$entity->status = NODE_PUBLISHED;
$entity->save();
$entity->setPublished()->save();
}
/**
......
......@@ -20,8 +20,7 @@ class StickyNode extends ActionBase {
* {@inheritdoc}
*/
public function execute($entity = NULL) {
$entity->sticky = NODE_STICKY;
$entity->save();
$entity->setSticky(TRUE)->save();
}
/**
......
......@@ -20,8 +20,7 @@ class UnpublishNode extends ActionBase {
* {@inheritdoc}
*/
public function execute($entity = NULL) {
$entity->status = NODE_NOT_PUBLISHED;
$entity->save();
$entity->setUnpublished()->save();
}
/**
......
......@@ -20,8 +20,7 @@ class UnstickyNode extends ActionBase {
* {@inheritdoc}
*/
public function execute($entity = NULL) {
$entity->sticky = NODE_NOT_STICKY;
$entity->save();
$entity->setSticky(FALSE)->save();
}
/**
......
......@@ -4,6 +4,7 @@
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
use Drupal\Core\Form\FormStateInterface;
use Drupal\node\NodeInterface;
/**
* Provides specific access control for the node entity type.
......@@ -38,7 +39,7 @@ protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS')
// modules in use on the site. As long as one access control module is there,
// it is supposed to handle this check.
if (!$this->currentUser->hasPermission('bypass node access') && !count($this->moduleHandler->getImplementations('node_grants'))) {
$query->condition('status', NODE_PUBLISHED);
$query->condition('status', NodeInterface::PUBLISHED);
}
return $query;
}
......
......@@ -2,6 +2,8 @@
namespace Drupal\node\Tests;
use Drupal\node\NodeInterface;
/**
* Tests the output of node links (read more, add new comment, etc).
*
......@@ -22,7 +24,7 @@ class NodeLinksTest extends NodeTestBase {
public function testHideLinks() {
$node = $this->drupalCreateNode(array(
'type' => 'article',
'promote' => NODE_PROMOTED,
'promote' => NodeInterface::PROMOTED,
));
// Links are displayed by default.
......
......@@ -2,6 +2,8 @@
namespace Drupal\node\Tests\Views;
use Drupal\node\NodeInterface;
/**
* Tests the node.status_extra field handler.
*
......@@ -28,14 +30,14 @@ public function testStatusExtra() {
// Create one published and one unpublished node by the admin.
$node_published = $this->drupalCreateNode(array('uid' => $admin_user->id()));
$node_unpublished = $this->drupalCreateNode(array('uid' => $admin_user->id(), 'status' => NODE_NOT_PUBLISHED));
$node_unpublished = $this->drupalCreateNode(['uid' => $admin_user->id(), 'status' => NodeInterface::NOT_PUBLISHED]);
// Create one unpublished node by a certain author user.
$node_unpublished2 = $this->drupalCreateNode(array('uid' => $node_author->id(), 'status' => NODE_NOT_PUBLISHED));
$node_unpublished2 = $this->drupalCreateNode(['uid' => $node_author->id(), 'status' => NodeInterface::NOT_PUBLISHED]);
// Create one unpublished node by a user who does not have the `view own
// unpublished content` permission.
$node_unpublished3 = $this->drupalCreateNode(array('uid' => $node_author_not_unpublished->id(), 'status' => NODE_NOT_PUBLISHED));
$node_unpublished3 = $this->drupalCreateNode(['uid' => $node_author_not_unpublished->id(), 'status' => NodeInterface::NOT_PUBLISHED]);
// The administrator should simply see all nodes.
$this->drupalLogin($admin_user);
......
......@@ -5,6 +5,7 @@
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -46,7 +47,7 @@ public static function create(ContainerInterface $container) {
*/
public function latest() {
$nids = $this->entityQuery->get('node')
->condition('status', NODE_PUBLISHED)
->condition('status', NodeInterface::PUBLISHED)
->sort('created', 'DESC')
->range(0, 3)
->execute();
......
......@@ -6,6 +6,7 @@
use Drupal\Core\Language\LanguageInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
use Drupal\node\NodeInterface;
/**
* Enables the page cache and tests its cache tags in various scenarios.
......@@ -44,7 +45,7 @@ function testPageCacheTags() {
'body' => array(
0 => array('value' => 'Body 1', 'format' => 'basic_html'),
),
'promote' => NODE_PROMOTED,
'promote' => NodeInterface::PROMOTED,
));
$author_2 = $this->drupalCreateUser();
$node_2 = $this->drupalCreateNode(array(
......@@ -53,7 +54,7 @@ function testPageCacheTags() {
'body' => array(
0 => array('value' => 'Body 2', 'format' => 'full_html'),
),
'promote' => NODE_PROMOTED,
'promote' => NodeInterface::PROMOTED,
));
// Place a block, but only make it visible on full node page 2.
......
......@@ -143,7 +143,7 @@ protected function setUp() {
// Create article.
$article_settings = array(
'type' => 'article',
'promote' => NODE_PROMOTED,
'promote' => NodeInterface::PROMOTED,
'field_image' => array(
array(
'target_id' => $this->image->id(),
......@@ -157,7 +157,7 @@ protected function setUp() {
);
$this->article = $this->drupalCreateNode($article_settings);
// Create second article to test teaser list.
$this->drupalCreateNode(array('type' => 'article', 'promote' => NODE_PROMOTED,));
$this->drupalCreateNode(['type' => 'article', 'promote' => NodeInterface::PROMOTED]);
// Create article comment.
$this->articleComment = $this->saveComment($this->article->id(), $this->webUser->id(), NULL, 0);
......
......@@ -3,6 +3,7 @@
namespace Drupal\system\Tests\Common;
use Drupal\simpletest\WebTestBase;
use Drupal\node\NodeInterface;
/**
* Tests that anonymous users are not served any JavaScript in the Standard
......@@ -27,7 +28,7 @@ protected function setUp() {
public function testNoJavaScript() {
// Create a node that is listed on the frontpage.
$this->drupalCreateNode(array(
'promote' => NODE_PROMOTED,
'promote' => NodeInterface::PROMOTED,
));
$user = $this->drupalCreateUser();
......
......@@ -7,6 +7,7 @@
use Drupal\Core\Language\LanguageInterface;
use Drupal\comment\CommentInterface;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\user\Entity\User;
use Drupal\comment\Entity\Comment;
......@@ -83,19 +84,19 @@ public function testNodeHandler() {
$node_values = array(
'published1' => array(
'type' => 'article',
'status' => NODE_PUBLISHED,
'status' => NodeInterface::PUBLISHED,
'title' => 'Node published1 (<&>)',
'uid' => 1,
),
'published2' => array(
'type' => 'article',
'status' => NODE_PUBLISHED,
'status' => NodeInterface::PUBLISHED,
'title' => 'Node published2 (<&>)',
'uid' => 1,
),
'unpublished' => array(
'type' => 'article',
'status' => NODE_NOT_PUBLISHED,
'status' => NodeInterface::NOT_PUBLISHED,
'title' => 'Node unpublished (<&>)',
'uid' => 1,
),
......
......@@ -6,6 +6,7 @@
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\comment\CommentInterface;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\node\NodeInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\comment\Entity\Comment;
use Drupal\taxonomy\Entity\Term;
......@@ -102,7 +103,7 @@ protected function setUp() {
$this->node = $this->drupalCreateNode(array(
'title' => $this->xssLabel,
'type' => 'article',
'promote' => NODE_PROMOTED,
'promote' => NodeInterface::PROMOTED,
'field_tags' => array(array('target_id' => $this->term->id())),
));
......
......@@ -3,6 +3,7 @@
namespace Drupal\views\Tests;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\NodeInterface;
/**
* Tests search integration filters with multilingual nodes.
......@@ -60,7 +61,7 @@ public function testMultilingualSearchFilter() {
$node = $this->drupalCreateNode($values);
// "Translate" this node into Spanish, with title "pizza".
$node->addTranslation('es', array('title' => 'pizza', 'status' => NODE_PUBLISHED));
$node->addTranslation('es', ['title' => 'pizza', 'status' => NodeInterface::PUBLISHED]);
$node->save();
// Run cron so that the search index tables are updated.
......
......@@ -8,6 +8,7 @@
use Drupal\Core\Menu\DefaultMenuLinkTreeManipulators;
use Drupal\Core\Menu\MenuLinkTreeElement;
use Drupal\Tests\UnitTestCase;
use Drupal\node\NodeInterface;
/**
* Tests the default menu link tree manipulators.
......@@ -295,7 +296,7 @@ public function testCheckNodeAccess() {
->with('nid', array(1, 2, 3, 4));
$query->expects($this->at(1))
->method('condition')
->with('status', NODE_PUBLISHED);
->with('status', NodeInterface::PUBLISHED);
$query->expects($this->once())
->method('execute')
->willReturn(array(1, 2, 4));
......@@ -338,7 +339,3 @@ public function testCheckNodeAccess() {
}
}
if (!defined('NODE_PUBLISHED')) {
define('NODE_PUBLISHED', 1);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment