diff core/modules/content_moderation/src/ModerationInformation.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children 12f9dff5fda9
line wrap: on
line diff
--- a/core/modules/content_moderation/src/ModerationInformation.php	Thu Feb 28 11:14:44 2019 +0000
+++ b/core/modules/content_moderation/src/ModerationInformation.php	Thu Feb 28 13:11:55 2019 +0000
@@ -4,16 +4,20 @@
 
 use Drupal\Core\Entity\ContentEntityInterface;
 use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\EntityPublishedInterface;
 use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
 use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\TypedData\TranslatableInterface;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 
 /**
  * General service for moderation-related questions about Entity API.
  */
 class ModerationInformation implements ModerationInformationInterface {
 
+  use StringTranslationTrait;
+
   /**
    * The entity type manager.
    *
@@ -171,6 +175,10 @@
   public function isDefaultRevisionPublished(ContentEntityInterface $entity) {
     $workflow = $this->getWorkflowForEntity($entity);
     $default_revision = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId())->load($entity->id());
+    // If no default revision could be loaded, the entity has not yet been
+    // saved. In this case the moderation_state of the unsaved entity can be
+    // used, since once saved it will become the default.
+    $default_revision = $default_revision  ?: $entity;
 
     // Ensure we are checking all translations of the default revision.
     if ($default_revision instanceof TranslatableInterface && $default_revision->isTranslatable()) {
@@ -205,4 +213,16 @@
     return NULL;
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function getUnsupportedFeatures(EntityTypeInterface $entity_type) {
+    $features = [];
+    // Test if entity is publishable.
+    if (!$entity_type->entityClassImplements(EntityPublishedInterface::class)) {
+      $features['publishing'] = $this->t("@entity_type_plural_label do not support publishing statuses. For example, even after transitioning from a published workflow state to an unpublished workflow state they will still be visible to site visitors.", ['@entity_type_plural_label' => $entity_type->getCollectionLabel()]);
+    }
+    return $features;
+  }
+
 }