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
parent
a99a141362
commit
2d933ecf71
|
@ -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;
|
||||
|
@ -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 @@ class ContentModerationConfigureEntityTypesForm extends FormBase {
|
|||
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',
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue