Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / content_moderation / src / Form / ContentModerationConfigureEntityTypesForm.php
index e181d4031b3f3ed3a37db20dc5594c45168542f2..d13ce9301c5d0a08bf1f0233289e5bdb4c752da9 100644 (file)
@@ -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;
   }
 
   /**
@@ -108,6 +119,7 @@ class ContentModerationConfigureEntityTypesForm extends FormBase {
         // Add the bundle to the options if it's not enabled on a workflow,
         // unless the workflow it's enabled on is this one.
         $options[$bundle_id] = [
+          'title' => ['data' => ['#title' => $bundle['label']]],
           'type' => $bundle['label'],
         ];
         // Add the bundle to the list of default values if it's enabled on this
@@ -132,6 +144,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',