class ModerationHandler in Workbench Moderation 8
Same name and namespace in other branches
- 8.2 src/Entity/Handler/ModerationHandler.php \Drupal\workbench_moderation\Entity\Handler\ModerationHandler
Common customizations for most/all entities.
This class is intended primarily as a base class.
Hierarchy
- class \Drupal\workbench_moderation\Entity\Handler\ModerationHandler implements EntityHandlerInterface, ModerationHandlerInterface uses StringTranslationTrait
Expanded class hierarchy of ModerationHandler
1 file declares its use of ModerationHandler
File
- src/
Entity/ Handler/ ModerationHandler.php, line 19
Namespace
Drupal\workbench_moderation\Entity\HandlerView source
class ModerationHandler implements ModerationHandlerInterface, EntityHandlerInterface {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static();
}
/**
* {@inheritdoc}
*/
public function onPresave(ContentEntityInterface $entity, $default_revision, $published_state) {
// When entities are syncing, content moderation should not force a new
// revision to be created and should not update the default status of a
// revision. This is useful if changes are being made to entities or
// revisions which are not part of editorial updates triggered by normal
// content changes.
if (!$entity
->isSyncing()) {
$entity
->setNewRevision(TRUE);
$entity
->isDefaultRevision($default_revision);
}
// Update publishing status if it can be updated and if it needs updating.
if ($entity instanceof EntityPublishedInterface && $entity
->isPublished() !== $published_state) {
$published_state ? $entity
->setPublished() : $entity
->setUnpublished();
}
}
/**
* {@inheritdoc}
*/
public function onBundleModerationConfigurationFormSubmit(ConfigEntityInterface $bundle) {
// The Revisions portion of Entity API is not uniformly applied or
// consistent. Until that's fixed in core, we'll make a best-attempt to
// apply it to the common entity patterns so as to avoid every entity type
// needing to implement this method, although some will still need to do so
// for now. This is the API that should be universal, but isn't yet.
// See NodeType for an example.
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();
}
/**
* {@inheritdoc}
*/
public function enforceRevisionsEntityFormAlter(array &$form, FormStateInterface $form_state, $form_id) {
}
/**
* {@inheritdoc}
*/
public function enforceRevisionsBundleFormAlter(array &$form, FormStateInterface $form_state, $form_id) {
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ModerationHandler:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface:: |
|
ModerationHandler:: |
public | function |
Alters bundle forms to enforce revision handling. Overrides ModerationHandlerInterface:: |
2 |
ModerationHandler:: |
public | function |
Alters entity forms to enforce revision handling. Overrides ModerationHandlerInterface:: |
2 |
ModerationHandler:: |
public | function |
Operates on the bundle definition that has been marked as moderatable. Overrides ModerationHandlerInterface:: |
|
ModerationHandler:: |
public | function |
Work to be done before saving en entity. Overrides ModerationHandlerInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |