62e504e4c0e2f3b5072aea81b52bbd9f866b2dfc
[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 class ModerationHandler implements ModerationHandlerInterface, EntityHandlerInterface {
19
20   use StringTranslationTrait;
21
22   /**
23    * {@inheritdoc}
24    */
25   public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
26     return new static();
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   public function onPresave(ContentEntityInterface $entity, $default_revision, $published_state) {
33     // This is probably not necessary if configuration is setup correctly.
34     $entity->setNewRevision(TRUE);
35     $entity->isDefaultRevision($default_revision);
36
37     // Update publishing status if it can be updated and if it needs updating.
38     if (($entity instanceof EntityPublishedInterface) && $entity->isPublished() !== $published_state) {
39       $published_state ? $entity->setPublished() : $entity->setUnpublished();
40     }
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function enforceRevisionsEntityFormAlter(array &$form, FormStateInterface $form_state, $form_id) {
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function enforceRevisionsBundleFormAlter(array &$form, FormStateInterface $form_state, $form_id) {
53   }
54
55 }