c44ab098413f4cd15c64fd8d76808ea7a04dc212
[yaffs-website] / web / core / modules / content_moderation / src / Entity / Handler / ModerationHandler.php
1 <?php
2
3 namespace Drupal\content_moderation\Entity\Handler;
4
5 use Drupal\Core\Entity\ContentEntityInterface;
6 use Drupal\Core\Entity\EntityHandlerInterface;
7 use Drupal\Core\Entity\EntityPublishedInterface;
8 use Drupal\Core\Entity\EntityTypeInterface;
9 use Drupal\Core\Form\FormStateInterface;
10 use Drupal\Core\StringTranslation\StringTranslationTrait;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
12
13 /**
14  * Common customizations for most/all entities.
15  *
16  * This class is intended primarily as a base class.
17  *
18  * @internal
19  */
20 class ModerationHandler implements ModerationHandlerInterface, EntityHandlerInterface {
21
22   use StringTranslationTrait;
23
24   /**
25    * {@inheritdoc}
26    */
27   public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
28     return new static();
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function onPresave(ContentEntityInterface $entity, $default_revision, $published_state) {
35     // This is probably not necessary if configuration is setup correctly.
36     $entity->setNewRevision(TRUE);
37     $entity->isDefaultRevision($default_revision);
38
39     // Update publishing status if it can be updated and if it needs updating.
40     if (($entity instanceof EntityPublishedInterface) && $entity->isPublished() !== $published_state) {
41       $published_state ? $entity->setPublished() : $entity->setUnpublished();
42     }
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   public function enforceRevisionsEntityFormAlter(array &$form, FormStateInterface $form_state, $form_id) {
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function enforceRevisionsBundleFormAlter(array &$form, FormStateInterface $form_state, $form_id) {
55   }
56
57 }