class ModerationHandler implements ModerationHandlerInterface, EntityHandlerInterface (View source)

internal  
 

Common customizations for most/all entities.

This class is intended primarily as a base class.

Traits

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Properties

protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait

Methods

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

createInstance(ContainerInterface $container, EntityTypeInterface $entity_type)

Instantiates a new instance of this entity handler.

bool
isModeratedEntity(ContentEntityInterface $entity)

Determines if an entity should be moderated.

onPresave(ContentEntityInterface $entity, bool $default_revision, bool $published_state)

Operates on moderated content entities preSave().

enforceRevisionsEntityFormAlter(array $form, FormStateInterface $form_state, string $form_id)

Alters entity forms to enforce revision handling.

enforceRevisionsBundleFormAlter(array $form, FormStateInterface $form_state, string $form_id)

Alters bundle forms to enforce revision handling.

Details

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

static EntityHandlerInterface createInstance(ContainerInterface $container, EntityTypeInterface $entity_type)

Instantiates a new instance of this entity handler.

This is a factory method that returns a new instance of this object. The factory should pass any needed dependencies into the constructor of this object, but not the container itself. Every call to this method must return a new instance of this object; that is, it may not implement a singleton.

Parameters

ContainerInterface $container

The service container this object should use.

EntityTypeInterface $entity_type

The entity type definition.

Return Value

EntityHandlerInterface

A new instance of the entity handler.

bool isModeratedEntity(ContentEntityInterface $entity)

Determines if an entity should be moderated.

At the workflow level, moderation is enabled or disabled for entire entity types or bundles. After a bundle has been enabled, there maybe be further decisions each entity type may make to evaluate if a given entity is appropriate to be included in a moderation workflow. The handler is only consulted after the user has configured the associated entity type and bundle to be included in a moderation workflow.

Returning FALSE will remove the moderation state field widget from the associated entity form and opt out of all moderation related entity semantics, such as creating new revisions and changing the publishing status of a revision.

Parameters

ContentEntityInterface $entity

The entity we may be moderating.

Return Value

bool

TRUE if this entity should be moderated, FALSE otherwise.

onPresave(ContentEntityInterface $entity, bool $default_revision, bool $published_state)

Operates on moderated content entities preSave().

Parameters

ContentEntityInterface $entity

The entity to modify.

bool $default_revision

Whether the new revision should be made the default revision.

bool $published_state

Whether the state being transitioned to is a published state or not.

enforceRevisionsEntityFormAlter(array $form, FormStateInterface $form_state, string $form_id)

Alters entity forms to enforce revision handling.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

string $form_id

The form id.

enforceRevisionsBundleFormAlter(array $form, FormStateInterface $form_state, string $form_id)

Alters bundle forms to enforce revision handling.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

string $form_id

The form id.