comparison 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
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
2 2
3 namespace Drupal\content_moderation; 3 namespace Drupal\content_moderation;
4 4
5 use Drupal\Core\Entity\ContentEntityInterface; 5 use Drupal\Core\Entity\ContentEntityInterface;
6 use Drupal\Core\Entity\EntityInterface; 6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Entity\EntityPublishedInterface;
7 use Drupal\Core\Entity\EntityTypeBundleInfoInterface; 8 use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
8 use Drupal\Core\Entity\EntityTypeInterface; 9 use Drupal\Core\Entity\EntityTypeInterface;
9 use Drupal\Core\Entity\EntityTypeManagerInterface; 10 use Drupal\Core\Entity\EntityTypeManagerInterface;
10 use Drupal\Core\TypedData\TranslatableInterface; 11 use Drupal\Core\TypedData\TranslatableInterface;
12 use Drupal\Core\StringTranslation\StringTranslationTrait;
11 13
12 /** 14 /**
13 * General service for moderation-related questions about Entity API. 15 * General service for moderation-related questions about Entity API.
14 */ 16 */
15 class ModerationInformation implements ModerationInformationInterface { 17 class ModerationInformation implements ModerationInformationInterface {
18
19 use StringTranslationTrait;
16 20
17 /** 21 /**
18 * The entity type manager. 22 * The entity type manager.
19 * 23 *
20 * @var \Drupal\Core\Entity\EntityTypeManagerInterface 24 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
169 * {@inheritdoc} 173 * {@inheritdoc}
170 */ 174 */
171 public function isDefaultRevisionPublished(ContentEntityInterface $entity) { 175 public function isDefaultRevisionPublished(ContentEntityInterface $entity) {
172 $workflow = $this->getWorkflowForEntity($entity); 176 $workflow = $this->getWorkflowForEntity($entity);
173 $default_revision = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId())->load($entity->id()); 177 $default_revision = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId())->load($entity->id());
178 // If no default revision could be loaded, the entity has not yet been
179 // saved. In this case the moderation_state of the unsaved entity can be
180 // used, since once saved it will become the default.
181 $default_revision = $default_revision ?: $entity;
174 182
175 // Ensure we are checking all translations of the default revision. 183 // Ensure we are checking all translations of the default revision.
176 if ($default_revision instanceof TranslatableInterface && $default_revision->isTranslatable()) { 184 if ($default_revision instanceof TranslatableInterface && $default_revision->isTranslatable()) {
177 // Loop through each language that has a translation. 185 // Loop through each language that has a translation.
178 foreach ($default_revision->getTranslationLanguages() as $language) { 186 foreach ($default_revision->getTranslationLanguages() as $language) {
203 return $this->entityTypeManager->getStorage('workflow')->load($bundles[$entity->bundle()]['workflow']); 211 return $this->entityTypeManager->getStorage('workflow')->load($bundles[$entity->bundle()]['workflow']);
204 }; 212 };
205 return NULL; 213 return NULL;
206 } 214 }
207 215
216 /**
217 * {@inheritdoc}
218 */
219 public function getUnsupportedFeatures(EntityTypeInterface $entity_type) {
220 $features = [];
221 // Test if entity is publishable.
222 if (!$entity_type->entityClassImplements(EntityPublishedInterface::class)) {
223 $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()]);
224 }
225 return $features;
226 }
227
208 } 228 }