Problem/Motivation

Currently module provide tab which allows to Publish/Unpublish node only after it was saved. Which is not very good sometimes.
However core Node module has Un/Publish options on node save but it shown only for users with 'administer nodes' permissions.
Here is the issue which describes it more https://www.drupal.org/node/2798601

Proposed resolution

As Publish Content module provides additional options for publish functionality we can implement more precise check if user allowed to see those buttons, and add them.
Attaching a patch which alter node form, does some checking and adds buttons which allow user with proper permissions to chose how to save new content, published or not.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tarasich created an issue. See original summary.

churel’s picture

Patch works great for me. Thing is if we add the button why do we still need the publish/unpublish tab? Should we remove it in the same patch?

andypost’s picture

+++ b/publishcontent.module
@@ -0,0 +1,67 @@
+  $account = \Drupal::currentUser();
...
+    && !\Drupal::currentUser()->hasPermission('administer nodes')

use $account->hasPermission() instead of accessing \Drupal again

mariiadeny’s picture

andypost’s picture

please add interdiff from previous patch https://www.drupal.org/documentation/git/interdiff

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to go

JonMcL’s picture

I could be wrong, but I don't think this actually works. The dropbutton shows up correctly and is updated correctly depended on status, but the button does not seem to change the status of the node when clicked.

I see in the code that the button elements have booleans set in ['#published_status'] but I am not sure if anything is reacting to that setting.

bluemoonj’s picture

The patch works fine on 8.3, however since now we have unpublish and publish in Save button, then we don't need the Publish/Unpublish tab at top anymore. We created a patch to hide this tab by introduced a new permission "show publish/unpublish tab", you can check or uncheck this box to show or hide the publish/unpublish tab.

espurnes’s picture

Status: Reviewed & tested by the community » Needs work

#4 adds dropdown button with "Save and publish" and "Save as unpublished" but any option saves the content as published.
As JonMcL says the "The dropbutton shows up correctly and is updated correctly depended on status, but the button does not seem to change the status of the node when clicked.".

I tried #8 patch on 8.4.4, by default hides the publishing tabs. They can be shown checking "Show publish/unpublish tab" permission under "/admin/people/permissions". But the problem with the dropdown button is still there. It doesn't change the status of the content.

Tabs works just fine.

Needs work.

ayalon’s picture

The patch is a good idea. But it does not work with Drupal 8.4. There the dropdown button was replaced by a simple checkbox. The patch has to be adopted accordingly.

See here:
https://www.drupal.org/project/drupal/issues/2068063