Problem/Motivation

We should move constants(NODE_PUBLISHED, NODE_PROMOTED etc.) from node.module to a proper place. The node interface is a good one. The actual name can still be discussed.

Proposed resolution

  • NODE_NOT_PUBLISHED => NodeInterface::NOT_PUBLISHED
  • NODE_PUBLISHED => NodeInterface::PUBLISHED
  • NODE_NOT_PROMOTED => NodeInterface::NOT_PROMOTED
  • NODE_PROMOTED => NodeInterface::PROMOTED
  • NODE_NOT_STICKY => NodeInterface::NOT_STICKY
  • NODE_STICKY => NodeInterface::STICKY

For BC reasons the node.module constants will be deprecated.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Comments

l0ke’s picture

Do you mean to move only NODE_PUBLISHED, or may be to move all constants from node.module to NodeInterface?
Also i think STATUS_PUBLISHED is a little more consistent.

dawehner’s picture

Yeah i guess other constants would be helpful as well.

l0ke’s picture

Assigned: Unassigned » l0ke
l0ke’s picture

Status: Active » Needs review
StatusFileSize
new29.28 KB

Moved. Named as:

  • NodeInterface::STATUS_NOT_PUBLISHED
  • NodeInterface::STATUS_PUBLISHED
  • NodeInterface::OPTION_NOT_PROMOTED
  • NodeInterface::OPTION_PROMOTED
  • NodeInterface::OPTION_NOT_STICKY
  • NodeInterface::OPTION_STICKY
  • NodeInterface::ACCESS_ALLOW
  • NodeInterface::ACCESS_DENY
  • NodeInterface::ACCESS_IGNORE

Status: Needs review » Needs work

The last submitted patch, 4: move-node-constatnts-2313095-4.patch, failed testing.

l0ke’s picture

Version: 8.x-dev » 8.0.x-dev

Status: Needs work » Needs review
dawehner’s picture

+1
It would be great to write an issue summary and prepare maybe a change notice. Note: We node maintainer should probably have a quick look.

l0ke’s picture

Title: Replace NODE_PUBLISHED with NodeInterface::STATUS_PUBLIC » Move node constants to NodeInterface
Issue summary: View changes
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

I am fine with that.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

Yep we need a change record for this.

garphy’s picture

Assigned: l0ke » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs change record

Draft change record created at https://www.drupal.org/node/2316145

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Seems reasonable for now.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 4: move-node-constatnts-2313095-4.patch, failed testing.

l0ke’s picture

Status: Needs work » Needs review
StatusFileSize
new29 KB

Reroll.

m1r1k’s picture

Issue tags: +#ams2014contest

Status: Needs review » Needs work

The last submitted patch, 15: move-node-constatnts-2313095-15.patch, failed testing.

l0ke’s picture

Status: Needs work » Needs review
Issue tags: -
StatusFileSize
new27.96 KB

Reroll.

umarzaffer’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 19: move-node-constatnts-2313095-19.patch, failed testing.

l0ke’s picture

Status: Needs work » Needs review
Issue tags: +Amsterdam2014
StatusFileSize
new22.64 KB

Re-roll the patch.

Status: Needs review » Needs work

The last submitted patch, 23: move-node-constatnts-2313095-23.patch, failed testing.

mrjmd’s picture

Status: Needs work » Needs review
StatusFileSize
new22.75 KB

Reroll attached.

rnield’s picture

Issue tags: +Needs reroll

DrupalConLA first time reviewer. Patch #26 appears to need to be re-rolled. Since this touches so many places I will not attempt to reroll.

umarzaffer’s picture

StatusFileSize
new23.54 KB

While re-rolling a new patch I:
1. Downloaded the most recent patch (#26) which failed to apply.
2. Created a new patch after checking out latest changes from 8.0.x branch.

Status: Needs review » Needs work

The last submitted patch, 28: move-node-constants-2313095-28.patch, failed testing.

umarzaffer’s picture

Status: Needs work » Needs review
StatusFileSize
new23.48 KB

Recreating patch as previous one failed for having use Drupal\node\NodeInterface; statement twice in a file.

leeotzu’s picture

Status: Needs review » Reviewed & tested by the community

The patch was applied successfully.

alexpott’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Reviewed & tested by the community » Postponed
Issue tags: -Needs reroll

Unfortunately this change does not pass the beta evaluation. See https://www.drupal.org/core/beta-changes for more information. It would possible to deprecate the constants and add the new constants to NodeInterface - however even this would not be permitted in beta because it would still be a normal task with no tangible benefits at this point in the Drupal 8 release cycle. Given that doing this change is possible in a non bc breaking manner I'm going to postpone this to 8.1

+++ b/core/modules/node/node.module
@@ -31,36 +31,6 @@
 /**
- * Denotes that the node is not published.
- */
-const NODE_NOT_PUBLISHED = 0;
-
-/**
- * Denotes that the node is published.
- */
-const NODE_PUBLISHED = 1;
-
-/**
- * Denotes that the node is not promoted to the front page.
- */
-const NODE_NOT_PROMOTED = 0;
-
-/**
- * Denotes that the node is promoted to the front page.
- */
-const NODE_PROMOTED = 1;
-
-/**
- * Denotes that the node is not sticky at the top of the page.
- */
-const NODE_NOT_STICKY = 0;
-
-/**
- * Denotes that the node is sticky at the top of the page.
- */
-const NODE_STICKY = 1;

Removing these constants will break existing Drupal 8 contrib.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

berdir’s picture

Status: Postponed » Needs work

Unpostponing. We can deprecate them now.

claudiu.cristea’s picture

Assigned: Unassigned » claudiu.cristea

.

claudiu.cristea’s picture

Assigned: claudiu.cristea » Unassigned
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Novice, -Amsterdam2014
StatusFileSize
new27 KB

Updated the IS. I didn't add an interdiff as is not relevant.

claudiu.cristea’s picture

Issue summary: View changes

.

Anonymous’s picture

I applied the #37 patch. Then I tried to find references to these constants:

NODE_NOT_PUBLISHED
NODE_PUBLISHED
NODE_NOT_PROMOTED
NODE_PROMOTED
NODE_NOT_STICKY
NODE_STICKY

They were only in the node.module file. Careful work!

+++ b/core/modules/node/src/Plugin/Action/PublishNode.php
@@ -4,6 +4,7 @@
+use Drupal\node\NodeInterface;

+++ b/core/modules/node/src/Plugin/Action/StickyNode.php
@@ -4,6 +4,7 @@
+use Drupal\node\NodeInterface;

Looks like we not use it now. But may be we can do changes like this:

-  public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
-    /** @var \Drupal\node\NodeInterface $object */
+  public function access(NodeInterface $object, AccountInterface $account = NULL, $return_as_object = FALSE) {
claudiu.cristea’s picture

StatusFileSize
new26.38 KB
new1.67 KB

@vaplas, thank you. Indeed those were unused statements.

UPDATE: interdiff-37-to-40.patch is in fact the interdiff

The last submitted patch, 37: 2313095-37.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 40: interdiff-37-to-40.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new2.22 KB
new28.11 KB

This patch revealed a bug in ModuleInstaller. The problem is that, on install, the module files "$module.module" and "$module.install" are loaded before the the module's PSR4 namespaces are registered. In this case, the code that is executed on file load (like constant declarations) cannot benefit from the new namespaces.

Status: Needs review » Needs work

The last submitted patch, 43: 2313095-43.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new28.1 KB
new513 bytes

Ouch, forgot a full qualified namespace inside.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

Cool solution! Looks like major fix for ModuleInstaller.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record, +Needs release manager review, +Needs framework manager review
+++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
@@ -175,12 +175,13 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
         // Update the module handler in order to load the module's code.
         // This allows the module to participate in hooks and its existence to
-        // be discovered by other modules.
+        // be discovered by other modules. The module code ("$module.module" and
+        // "$module.install" files) are loaded only after the kernel rebuild in
+        // order to make the PSR4 namespaces provided by this module available
+        // to its own code.
         // The current ModuleHandler instance is obsolete with the kernel
         // rebuild below.
         $this->moduleHandler->setModuleList($module_filenames);
-        $this->moduleHandler->load($module);
-        module_load_install($module);
 
         // Clear the static cache of system_rebuild_module_data() to pick up the
         // new module, since it merges the installation status of modules into
@@ -190,6 +191,10 @@ public function install(array $module_list, $enable_dependencies = TRUE) {

@@ -190,6 +191,10 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
         // Update the kernel to include it.
         $this->updateKernel($module_filenames);
 
+        // Load the module code ("$module.module" and "$module.install" files).
+        $this->moduleHandler->load($module);
+        module_load_install($module);

This change is a concern because there's a small possibility of regression here. It is possible a container compiler pass might use code from the .module file. I can't see a way around this. Going to get other framework manager / release manager opinions. But this part definitely deserves its own change record.

berdir’s picture

We can easily work around this by simply keeping the actual values in the old constants, that's what we did before.

Then we can move that change into a separate issue.

catch’s picture

Yeah completely agreed with #48, there's no reason to get the constants from the interface for deprecated code and we've never tried to do that before.

It's worth a follow-up to look at the wider issue, but let's look at that separately.

catch’s picture

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new3.57 KB
new26 KB

Hardcoded values for deprecated constants.

claudiu.cristea’s picture

Issue tags: -Needs change record
alexpott’s picture

@claudiu.cristea I updated the old CR (https://www.drupal.org/node/2316145) with you improvements and deleted your old one. We only needed another CR for the module installer changes that no longer are a part of this.

claudiu.cristea’s picture

We only needed another CR for the module installer changes that no longer are a part of this.

@alexpott, but that needs also its own issue, right?

claudiu.cristea’s picture

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

All the proposed changes are made, thus RTBC again.

catch’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/node/src/Entity/Node.php
@@ -228,7 +228,7 @@ public function isPromoted() {
+    $this->set('promote', $promoted ? NodeInterface::OPTION_PROMOTED : NodeInterface::OPTION_NOT_PROMOTED);

Why do these need to be OPTION_PROMOTED and OPTION_NOT_PROMOTED? Just PROMOTED and NOT_PROMOTED would do?

Same with PUBLISHED/NOT_PUBLISHED too really.

claudiu.cristea’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new25.66 KB
new20.63 KB

Fixed #57. Back to RTBC as it was only a simple renaming. Fixed also the IS.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

catch’s picture

Version: 8.4.x-dev » 8.3.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: +8.3.0 release notes

Committed/pushed to 8.4.x and cherry-picked to 8.3.x. Thanks!

  • catch committed 8dbd209 on 8.4.x
    Issue #2313095 by claudiu.cristea, l0ke, umarzaffer, mrjmd, dawehner,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.