summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGábor Hojtsy2018-05-31 12:00:17 (GMT)
committerGábor Hojtsy2018-05-31 12:00:17 (GMT)
commit2d933ecf711393f2278aa5a5a67f73f328191c0e (patch)
tree34a6dd1c8b8f24589974b56562ac1668740547a7
parenta99a1413621aad0f377c985662d44797bc5059fb (diff)
Issue #2851228 by timmillwood, matthieuscarset, Manuel Garcia, Sam152, Gábor Hojtsy, yoroy, tstoeckler, alexpott, Shiraz Dindar, Fabianx, nbchip: Warn users of what features are not available on a given entity type
-rw-r--r--core/modules/content_moderation/src/Form/ContentModerationConfigureEntityTypesForm.php26
-rw-r--r--core/modules/content_moderation/src/ModerationInformation.php16
-rw-r--r--core/modules/content_moderation/src/ModerationInformationInterface.php11
-rw-r--r--core/modules/content_moderation/tests/src/Functional/ContentModerationWorkflowTypeTest.php5
4 files changed, 56 insertions, 2 deletions
diff --git a/core/modules/content_moderation/src/Form/ContentModerationConfigureEntityTypesForm.php b/core/modules/content_moderation/src/Form/ContentModerationConfigureEntityTypesForm.php
index e181d40..352ce01 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\CloseDialogCommand;
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;
@@ -58,23 +60,32 @@ class ContentModerationConfigureEntityTypesForm extends FormBase {
protected $entityType;
/**
+ * The Messenger service.
+ *
+ * @var \Drupal\Core\Messenger\MessengerInterface
+ */
+ protected $messenger;
+
+ /**
* {@inheritdoc}
*/
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 @@ class ContentModerationConfigureEntityTypesForm extends FormBase {
];
}
+ // 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 f42ec33..9f35046 100644
--- a/core/modules/content_moderation/src/ModerationInformation.php
+++ b/core/modules/content_moderation/src/ModerationInformation.php
@@ -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.
*
@@ -205,4 +209,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;
+ }
+
}
diff --git a/core/modules/content_moderation/src/ModerationInformationInterface.php b/core/modules/content_moderation/src/ModerationInformationInterface.php
index 739c16b..c2368e9 100644
--- a/core/modules/content_moderation/src/ModerationInformationInterface.php
+++ b/core/modules/content_moderation/src/ModerationInformationInterface.php
@@ -163,4 +163,15 @@ interface ModerationInformationInterface {
*/
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 96461ac..40c227b 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 @@ class ContentModerationWorkflowTypeTest extends BrowserTestBase {
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.');
}
}