Commit 0f7a0719 authored by Crell's avatar Crell

Issue #2696829 by Crell, Bcwald: Remove published/unpublished operations when...

Issue #2696829 by Crell, Bcwald: Remove published/unpublished operations when WBM is enabled, as they no longer apply

Merge branch '2696829-bulk-operations' into 8.x-1.x
parents 6f29a328 d7dd6239
Workbench Moderation
====================
About this module
-----------------
Workbench Moderation (WBM) provides basic moderation support for revisionable content entities. That is, it allows
site administrators to define States that content can be in, Transitions between those States, and rules around who
is able to Transition content from one State to another, when.
In concept, any revision-aware content entity is supportable. In core, that includes Nodes and Block Content. However,
there may be a small amount of work needed to support additional content entities due to inconsistencies in the
Entity API.core. To add custom WBM integration for your entity type, annotate your entity to specify a moderation
handler class that extends \Drupal\workbench_moderation\Entity\Handler\ModerationHandler.
Installation
------------
WBM has no special installation instructions. The default configuration that ships with the module should cover most
typical use cases, with no need to configure additional States or Transitions. You are welcome to do so, however, and
to edit or remote any pre-defined State or Transition.
Note that when an entity is under moderation by this module, explicitly setting its published state (on nodes) or its
"make default revision" value (on all entities) will have no effect, because WBM will always overwrite those values based
on your configured State rules. That is most notable with regards to core's Publish and Unpublish actions for Bulk
Operations on nodes, as seen on /admin/content. Those actions will simply have no effect on a moderated node.
To avoid confusion, removing the actions from that view (or any similar views) is recommended.
1) Visit /admin/structure/views/view/content .
2) Configure: 'Content: Node operations bulk form' > change the Available actions to 'Only selected actions' > Deselect 'publish content' and 'unpublish content'.
3) Save view.
<?php
namespace Drupal\workbench_moderation\Plugin\Action;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\node\Plugin\Action\PublishNode;
use Drupal\workbench_moderation\ModerationInformationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Alternate action plugin that knows to opt-out of modifying moderated entites.
*
* @see PublishNode
*/
class ModerationOptOutPublishNode extends PublishNode implements ContainerFactoryPluginInterface {
/**
* @var \Drupal\workbench_moderation\ModerationInformationInterface
*/
protected $moderationInfo;
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModerationInformationInterface $mod_info) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->moderationInfo = $mod_info;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration, $plugin_id, $plugin_definition,
$container->get('workbench_moderation.moderation_information')
);
}
/**
* {@inheritdoc}
*/
public function execute($entity = NULL) {
if ($entity && $this->moderationInfo->isModeratableEntity($entity)) {
drupal_set_message($this->t('One or more entities were skipped as they are under moderation and may not be directly published or unpublished.'));
return;
}
parent::execute($entity);
}
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
$result = parent::access($object, $account, TRUE)
->andif(AccessResult::forbiddenIf($this->moderationInfo->isModeratableEntity($object))->addCacheableDependency($object));
return $return_as_object ? $result : $result->isAllowed();
}
}
<?php
namespace Drupal\workbench_moderation\Plugin\Action;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\node\Plugin\Action\UnpublishNode;
use Drupal\workbench_moderation\ModerationInformationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Alternate action plugin that knows to opt-out of modifying moderated entites.
*
* @see UnpublishNode
*/
class ModerationOptOutUnpublishNode extends UnpublishNode implements ContainerFactoryPluginInterface {
/**
* @var \Drupal\workbench_moderation\ModerationInformationInterface
*/
protected $moderationInfo;
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModerationInformationInterface $mod_info) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->moderationInfo = $mod_info;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration, $plugin_id, $plugin_definition,
$container->get('workbench_moderation.moderation_information')
);
}
/**
* {@inheritdoc}
*/
public function execute($entity = NULL) {
if ($entity && $this->moderationInfo->isModeratableEntity($entity)) {
drupal_set_message($this->t('One or more entities were skipped as they are under moderation and may not be directly published or unpublished.'));
return;
}
parent::execute($entity);
}
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
$result = parent::access($object, $account, TRUE)
->andif(AccessResult::forbiddenIf($this->moderationInfo->isModeratableEntity($object))->addCacheableDependency($object));
return $return_as_object ? $result : $result->isAllowed();
}
}
......@@ -17,6 +17,10 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\node\NodeInterface;
use Drupal\node\Plugin\Action\PublishNode;
use Drupal\node\Plugin\Action\UnpublishNode;
use Drupal\workbench_moderation\Plugin\Action\ModerationOptOutPublishNode;
use Drupal\workbench_moderation\Plugin\Action\ModerationOptOutUnpublishNode;
use Drupal\workbench_moderation\Plugin\Menu\EditTab;
/**
......@@ -193,6 +197,23 @@ function workbench_moderation_theme($existing, $type, $theme, $path) {
return $themes;
}
/**
* Implements hook_action_info_alter().
*/
function workbench_moderation_action_info_alter(&$definitions) {
// The publish/unpublish actions are not valid on moderated entities. So swap
// their implementations out for alternates that will become a no-op on a
// moderated node. If another module has already swapped out those classes,
// though, we'll be polite and do nothing.
if (isset($definitions['node_publish_action']['class']) && $definitions['node_publish_action']['class'] == PublishNode::class) {
$definitions['node_publish_action']['class'] = ModerationOptOutPublishNode::class;
}
if (isset($definitions['node_unpublish_action']['class']) && $definitions['node_unpublish_action']['class'] == UnpublishNode::class) {
$definitions['node_unpublish_action']['class'] = ModerationOptOutUnpublishNode::class;
}
}
/**
* Implements hook_views_data_alter().
*/
......
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