ModerationHandler.php in Workbench Moderation 8
File
src/Entity/Handler/ModerationHandler.php
View source
<?php
namespace Drupal\workbench_moderation\Entity\Handler;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityHandlerInterface;
use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ModerationHandler implements ModerationHandlerInterface, EntityHandlerInterface {
use StringTranslationTrait;
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static();
}
public function onPresave(ContentEntityInterface $entity, $default_revision, $published_state) {
if (!$entity
->isSyncing()) {
$entity
->setNewRevision(TRUE);
$entity
->isDefaultRevision($default_revision);
}
if ($entity instanceof EntityPublishedInterface && $entity
->isPublished() !== $published_state) {
$published_state ? $entity
->setPublished() : $entity
->setUnpublished();
}
}
public function onBundleModerationConfigurationFormSubmit(ConfigEntityInterface $bundle) {
if (method_exists($bundle, 'setNewRevision')) {
$bundle
->setNewRevision(TRUE);
}
elseif ($bundle
->get('new_revision') !== NULL) {
$bundle
->set('new_revision', TRUE);
}
elseif ($bundle
->get('revision') !== NULL) {
$bundle
->set('revision', TRUE);
}
$bundle
->save();
}
public function enforceRevisionsEntityFormAlter(array &$form, FormStateInterface $form_state, $form_id) {
}
public function enforceRevisionsBundleFormAlter(array &$form, FormStateInterface $form_state, $form_id) {
}
}