summaryrefslogtreecommitdiffstats
path: root/core/modules/content_moderation/src/Entity
diff options
context:
space:
mode:
authorAlex Pott2017-01-18 17:38:15 (GMT)
committerAlex Pott2017-01-18 17:38:15 (GMT)
commitd55b420af5a53c5c6459ba36ff99413b20dc5cee (patch)
tree7afa24b9d5b542f8bf9b5b9e6efe1c67d59253ce /core/modules/content_moderation/src/Entity
parentb1500e0704ffd222fc026d5fb71e177705001e81 (diff)
Issue #2812811 by Sam152, timmillwood, amateescu, alexpott, catch: Use EntityPublishedInterface during moderation of entities to add support beyond nodes
Diffstat (limited to 'core/modules/content_moderation/src/Entity')
-rw-r--r--core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php6
-rw-r--r--core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php31
2 files changed, 6 insertions, 31 deletions
diff --git a/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php b/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php
index 542cc84..62e504e 100644
--- a/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php
+++ b/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php
@@ -4,6 +4,7 @@ namespace Drupal\content_moderation\Entity\Handler;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityHandlerInterface;
+use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
@@ -32,6 +33,11 @@ class ModerationHandler implements ModerationHandlerInterface, EntityHandlerInte
// This is probably not necessary if configuration is setup correctly.
$entity->setNewRevision(TRUE);
$entity->isDefaultRevision($default_revision);
+
+ // Update publishing status if it can be updated and if it needs updating.
+ if (($entity instanceof EntityPublishedInterface) && $entity->isPublished() !== $published_state) {
+ $published_state ? $entity->setPublished() : $entity->setUnpublished();
+ }
}
/**
diff --git a/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php b/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php
index 247d352..76f00e0 100644
--- a/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php
+++ b/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php
@@ -3,7 +3,6 @@
namespace Drupal\content_moderation\Entity\Handler;
use Drupal\content_moderation\ModerationInformationInterface;
-use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -42,18 +41,6 @@ class NodeModerationHandler extends ModerationHandler {
/**
* {@inheritdoc}
*/
- public function onPresave(ContentEntityInterface $entity, $default_revision, $published_state) {
- if ($this->shouldModerate($entity, $published_state)) {
- parent::onPresave($entity, $default_revision, $published_state);
- // Only nodes have a concept of published.
- /** @var \Drupal\node\NodeInterface $entity */
- $entity->setPublished($published_state);
- }
- }
-
- /**
- * {@inheritdoc}
- */
public function enforceRevisionsEntityFormAlter(array &$form, FormStateInterface $form_state, $form_id) {
$form['revision']['#disabled'] = TRUE;
$form['revision']['#default_value'] = TRUE;
@@ -74,22 +61,4 @@ class NodeModerationHandler extends ModerationHandler {
}
}
- /**
- * Check if an entity's default revision and/or state needs adjusting.
- *
- * @param \Drupal\Core\Entity\ContentEntityInterface $entity
- * The entity to check.
- * @param bool $published_state
- * Whether the state being transitioned to is a published state or not.
- *
- * @return bool
- * TRUE when either the default revision or the state needs to be updated.
- */
- protected function shouldModerate(ContentEntityInterface $entity, $published_state) {
- // @todo clarify the first condition.
- // First condition is needed so you can add a translation.
- // Second condition checks to see if the published status has changed.
- return $entity->isDefaultTranslation() || $entity->isPublished() !== $published_state;
- }
-
}