Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / content_moderation / src / Form / EntityModerationForm.php
index 7d05c5c7fc78244469f81d1d52d405ed940fdedd..34af4ea50345c06f397024ce0f3ff3cacb5f6453 100644 (file)
@@ -8,12 +8,14 @@ use Drupal\Core\Entity\RevisionLogInterface;
 use Drupal\Core\Form\FormBase;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\content_moderation\ModerationInformationInterface;
-use Drupal\content_moderation\StateTransitionValidation;
+use Drupal\content_moderation\StateTransitionValidationInterface;
 use Drupal\workflows\Transition;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
  * The EntityModerationForm provides a simple UI for changing moderation state.
+ *
+ * @internal
  */
 class EntityModerationForm extends FormBase {
 
@@ -34,7 +36,7 @@ class EntityModerationForm extends FormBase {
   /**
    * The moderation state transition validation service.
    *
-   * @var \Drupal\content_moderation\StateTransitionValidation
+   * @var \Drupal\content_moderation\StateTransitionValidationInterface
    */
   protected $validation;
 
@@ -43,15 +45,15 @@ class EntityModerationForm extends FormBase {
    *
    * @param \Drupal\content_moderation\ModerationInformationInterface $moderation_info
    *   The moderation information service.
-   * @param \Drupal\content_moderation\StateTransitionValidation $validation
+   * @param \Drupal\content_moderation\StateTransitionValidationInterface $validation
    *   The moderation state transition validation service.
    * @param \Drupal\Component\Datetime\Time $time
    *   The time service.
    */
-  public function __construct(ModerationInformationInterface $moderation_info, StateTransitionValidation $validation, Time $time) {
+  public function __construct(ModerationInformationInterface $moderation_info, StateTransitionValidationInterface $validation, Time $time) {
     $this->moderationInfo = $moderation_info;
-    $this->time = $time;
     $this->validation = $validation;
+    $this->time = $time;
   }
 
   /**
@@ -126,6 +128,7 @@ class EntityModerationForm extends FormBase {
     ];
 
     $form['#theme'] = ['entity_moderation_form'];
+    $form['#attached']['library'][] = 'content_moderation/content_moderation';
 
     return $form;
   }
@@ -136,6 +139,9 @@ class EntityModerationForm extends FormBase {
   public function submitForm(array &$form, FormStateInterface $form_state) {
     /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
     $entity = $form_state->get('entity');
+    /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
+    $storage = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId());
+    $entity = $storage->createRevision($entity, $entity->isDefaultRevision());
 
     $new_state = $form_state->getValue('new_state');
 
@@ -148,7 +154,7 @@ class EntityModerationForm extends FormBase {
     }
     $entity->save();
 
-    drupal_set_message($this->t('The moderation state has been updated.'));
+    $this->messenger()->addStatus($this->t('The moderation state has been updated.'));
 
     $new_state = $this->moderationInfo->getWorkflowForEntity($entity)->getTypePlugin()->getState($new_state);
     // The page we're on likely won't be visible if we just set the entity to