diff --git a/core/modules/content_moderation/src/Form/ContentModerationConfigureEntityTypesForm.php b/core/modules/content_moderation/src/Form/ContentModerationConfigureEntityTypesForm.php index e181d4031b3f3ed3a37db20dc5594c45168542f2..352ce018972b5506d808d2fdb6f024e42af5442f 100644 --- a/core/modules/content_moderation/src/Form/ContentModerationConfigureEntityTypesForm.php +++ b/core/modules/content_moderation/src/Form/ContentModerationConfigureEntityTypesForm.php @@ -9,8 +9,10 @@ use Drupal\Core\Ajax\HtmlCommand; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\EventSubscriber\MainContentViewSubscriber; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Messenger\MessengerInterface; use Drupal\workflows\WorkflowInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -57,6 +59,13 @@ class ContentModerationConfigureEntityTypesForm extends FormBase { */ protected $entityType; + /** + * The Messenger service. + * + * @var \Drupal\Core\Messenger\MessengerInterface + */ + protected $messenger; + /** * {@inheritdoc} */ @@ -64,17 +73,19 @@ public static function create(ContainerInterface $container) { return new static( $container->get('entity_type.manager'), $container->get('entity_type.bundle.info'), - $container->get('content_moderation.moderation_information') + $container->get('content_moderation.moderation_information'), + $container->get('messenger') ); } /** * {@inheritdoc} */ - public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $bundle_info, ModerationInformationInterface $moderation_information) { + public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $bundle_info, ModerationInformationInterface $moderation_information, MessengerInterface $messenger) { $this->entityTypeManager = $entity_type_manager; $this->bundleInfo = $bundle_info; $this->moderationInformation = $moderation_information; + $this->messenger = $messenger; } /** @@ -132,6 +143,17 @@ public function buildForm(array $form, FormStateInterface $form_state, WorkflowI ]; } + // Get unsupported features for this entity type. + $warnings = $this->moderationInformation->getUnsupportedFeatures($this->entityType); + // Display message into the Ajax form returned. + if ($this->getRequest()->get(MainContentViewSubscriber::WRAPPER_FORMAT) == 'drupal_modal' && !empty($warnings)) { + $form['warnings'] = ['#type' => 'status_messages', '#weight' => -1]; + } + // Set warning message. + foreach ($warnings as $warning) { + $this->messenger->addWarning($warning); + } + $form['actions'] = ['#type' => 'actions']; $form['actions']['submit'] = [ '#type' => 'submit', diff --git a/core/modules/content_moderation/src/ModerationInformation.php b/core/modules/content_moderation/src/ModerationInformation.php index f42ec335586fc5da8360cf13292d16d3653796dc..9f350467be6ab1d772cdcf764e32522d628ce08a 100644 --- a/core/modules/content_moderation/src/ModerationInformation.php +++ b/core/modules/content_moderation/src/ModerationInformation.php @@ -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. * @@ -205,4 +209,16 @@ public function getWorkflowForEntity(ContentEntityInterface $entity) { 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; + } + } diff --git a/core/modules/content_moderation/src/ModerationInformationInterface.php b/core/modules/content_moderation/src/ModerationInformationInterface.php index 739c16b842bce895cac2a6f8c331a62b3370b653..c2368e9ff0b338db10e2c922b46bd8b31d10b45c 100644 --- a/core/modules/content_moderation/src/ModerationInformationInterface.php +++ b/core/modules/content_moderation/src/ModerationInformationInterface.php @@ -163,4 +163,15 @@ public function isDefaultRevisionPublished(ContentEntityInterface $entity); */ public function getWorkflowForEntity(ContentEntityInterface $entity); + /** + * Gets unsupported features for a given entity type. + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type to get the unsupported features for. + * + * @return array + * An array of unsupported features for this entity type. + */ + public function getUnsupportedFeatures(EntityTypeInterface $entity_type); + } diff --git a/core/modules/content_moderation/tests/src/Functional/ContentModerationWorkflowTypeTest.php b/core/modules/content_moderation/tests/src/Functional/ContentModerationWorkflowTypeTest.php index 96461ac07a14de06c5d5cbc211eae4ea69882a17..40c227b851d47aa14d643e131fe0a0abe137d7ed 100644 --- a/core/modules/content_moderation/tests/src/Functional/ContentModerationWorkflowTypeTest.php +++ b/core/modules/content_moderation/tests/src/Functional/ContentModerationWorkflowTypeTest.php @@ -19,6 +19,7 @@ class ContentModerationWorkflowTypeTest extends BrowserTestBase { public static $modules = [ 'content_moderation', 'node', + 'entity_test', ]; /** @@ -96,6 +97,10 @@ public function testNewWorkflow() { foreach ($types as $type) { $session->pageTextContains($type->label()); } + + // Ensure warning message are displayed for unsupported features. + $this->drupalGet('admin/config/workflow/workflows/manage/test/type/entity_test_rev'); + $this->assertSession()->pageTextContains('Test entity - revisions entities 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.'); } }