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.
*
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()) {
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;
+ }
+
}