PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php

http://github.com/drupal/drupal
PHP | 63 lines | 28 code | 10 blank | 25 comment | 3 complexity | ec18dd1b25979b2d0b19772de9a950c5 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. namespace Drupal\content_moderation\Entity\Handler;
  3. use Drupal\Core\Entity\ContentEntityInterface;
  4. use Drupal\Core\Entity\EntityHandlerInterface;
  5. use Drupal\Core\Entity\EntityPublishedInterface;
  6. use Drupal\Core\Entity\EntityTypeInterface;
  7. use Drupal\Core\Form\FormStateInterface;
  8. use Drupal\Core\StringTranslation\StringTranslationTrait;
  9. use Symfony\Component\DependencyInjection\ContainerInterface;
  10. /**
  11. * Common customizations for most/all entities.
  12. *
  13. * This class is intended primarily as a base class.
  14. *
  15. * @internal
  16. */
  17. class ModerationHandler implements ModerationHandlerInterface, EntityHandlerInterface {
  18. use StringTranslationTrait;
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
  23. return new static();
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function onPresave(ContentEntityInterface $entity, $default_revision, $published_state) {
  29. // When entities are syncing, content moderation should not force a new
  30. // revision to be created and should not update the default status of a
  31. // revision. This is useful if changes are being made to entities or
  32. // revisions which are not part of editorial updates triggered by normal
  33. // content changes.
  34. if (!$entity->isSyncing()) {
  35. $entity->setNewRevision(TRUE);
  36. $entity->isDefaultRevision($default_revision);
  37. }
  38. // Update publishing status if it can be updated and if it needs updating.
  39. if (($entity instanceof EntityPublishedInterface) && $entity->isPublished() !== $published_state) {
  40. $published_state ? $entity->setPublished() : $entity->setUnpublished();
  41. }
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function enforceRevisionsEntityFormAlter(array &$form, FormStateInterface $form_state, $form_id) {
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function enforceRevisionsBundleFormAlter(array &$form, FormStateInterface $form_state, $form_id) {
  52. }
  53. }