Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / content_moderation / src / ModerationInformation.php
index f42ec335586fc5da8360cf13292d16d3653796dc..286104ffd78cfb892e6baef3bfcc8d9ebd718687 100644 (file)
@@ -4,16 +4,20 @@ namespace Drupal\content_moderation;
 
 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 @@ class ModerationInformation implements ModerationInformationInterface {
   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 @@ class ModerationInformation implements ModerationInformationInterface {
     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;
+  }
+
 }