class ModerationInformation implements ModerationInformationInterface (View source)

General service for moderation-related questions about Entity API.

Traits

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

Properties

protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

protected EntityTypeBundleInfoInterface $bundleInfo

The bundle information service.

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.

__construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $bundle_info)

Creates a new ModerationInformation instance.

bool
isModeratedEntity(EntityInterface $entity)

Determines if an entity is moderated.

bool
isModeratedEntityType(EntityTypeInterface $entity_type)

Determines if an entity type has at least one moderated bundle.

bool
canModerateEntitiesOfEntityType(EntityTypeInterface $entity_type)

Determines if an entity type can have moderated entities.

bool
shouldModerateEntitiesOfBundle(EntityTypeInterface $entity_type, string $bundle)

Determines if an entity type/bundle entities should be moderated.

getLatestRevision(string $entity_type_id, int $entity_id)

Loads the latest revision of a specific entity.

int
getLatestRevisionId(string $entity_type_id, int $entity_id)

Returns the revision ID of the latest revision of the given entity.

int
getDefaultRevisionId(string $entity_type_id, int $entity_id)

Returns the revision ID of the default revision for the specified entity.

getAffectedRevisionTranslation(ContentEntityInterface $entity)

Returns the revision translation affected translation of a revision.

bool
isLatestRevision(ContentEntityInterface $entity)

Determines if an entity is a latest revision.

bool
hasPendingRevision(ContentEntityInterface $entity)

Determines if a pending revision exists for the specified entity.

bool
isLiveRevision(ContentEntityInterface $entity)

Determines if an entity is "live".

bool
isDefaultRevisionPublished(ContentEntityInterface $entity)

Determines if the default revision for the given entity is published.

getWorkflowForEntity(ContentEntityInterface $entity)

Gets the workflow for the given content entity.

getWorkflowForEntityTypeAndBundle(string $entity_type_id, string $bundle_id)

Gets the workflow for the given entity type and bundle.

array
getUnsupportedFeatures(EntityTypeInterface $entity_type)

Gets unsupported features for a given entity type.

getOriginalState(ContentEntityInterface $entity)

Gets the original or initial state of the given entity.

bool
isFirstTimeModeration(ContentEntityInterface $entity)

Determines if this entity is being moderated for the first time.

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

__construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $bundle_info)

Creates a new ModerationInformation instance.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

EntityTypeBundleInfoInterface $bundle_info

The bundle information service.

bool isModeratedEntity(EntityInterface $entity)

Determines if an entity is moderated.

Parameters

EntityInterface $entity

The entity we may be moderating.

Return Value

bool

TRUE if this entity is moderated, FALSE otherwise.

bool isModeratedEntityType(EntityTypeInterface $entity_type)

Determines if an entity type has at least one moderated bundle.

Parameters

EntityTypeInterface $entity_type

The entity type definition to check.

Return Value

bool

TRUE if an entity type has a moderated bundle, FALSE otherwise.

bool canModerateEntitiesOfEntityType(EntityTypeInterface $entity_type)

Determines if an entity type can have moderated entities.

Parameters

EntityTypeInterface $entity_type

An entity type object.

Return Value

bool

TRUE if this entity type can have moderated entities, FALSE otherwise.

bool shouldModerateEntitiesOfBundle(EntityTypeInterface $entity_type, string $bundle)

Determines if an entity type/bundle entities should be moderated.

Parameters

EntityTypeInterface $entity_type

The entity type definition to check.

string $bundle

The bundle to check.

Return Value

bool

TRUE if an entity type/bundle entities should be moderated, FALSE otherwise.

ContentEntityInterface|null getLatestRevision(string $entity_type_id, int $entity_id)

Loads the latest revision of a specific entity.

Parameters

string $entity_type_id

The entity type ID.

int $entity_id

The entity ID.

Return Value

ContentEntityInterface|null

The latest entity revision or NULL, if the entity type / entity doesn't exist.

int getLatestRevisionId(string $entity_type_id, int $entity_id)

Returns the revision ID of the latest revision of the given entity.

Parameters

string $entity_type_id

The entity type ID.

int $entity_id

The entity ID.

Return Value

int

The revision ID of the latest revision for the specified entity, or NULL if there is no such entity.

int getDefaultRevisionId(string $entity_type_id, int $entity_id)

Returns the revision ID of the default revision for the specified entity.

Parameters

string $entity_type_id

The entity type ID.

int $entity_id

The entity ID.

Return Value

int

The revision ID of the default revision, or NULL if the entity was not found.

ContentEntityInterface getAffectedRevisionTranslation(ContentEntityInterface $entity)

Returns the revision translation affected translation of a revision.

Parameters

ContentEntityInterface $entity

The content entity.

Return Value

ContentEntityInterface

The revision translation affected translation.

bool isLatestRevision(ContentEntityInterface $entity)

Determines if an entity is a latest revision.

Parameters

ContentEntityInterface $entity

A revisionable content entity.

Return Value

bool

TRUE if the specified object is the latest revision of its entity, FALSE otherwise.

bool hasPendingRevision(ContentEntityInterface $entity)

Determines if a pending revision exists for the specified entity.

Parameters

ContentEntityInterface $entity

The entity which may or may not have a pending revision.

Return Value

bool

TRUE if this entity has pending revisions available, FALSE otherwise.

bool isLiveRevision(ContentEntityInterface $entity)

Determines if an entity is "live".

A "live" entity revision is one whose latest revision is also the default, and whose moderation state, if any, is a published state.

Parameters

ContentEntityInterface $entity

The entity to check.

Return Value

bool

TRUE if the specified entity is a live revision, FALSE otherwise.

bool isDefaultRevisionPublished(ContentEntityInterface $entity)

Determines if the default revision for the given entity is published.

The default revision is the same as the entity retrieved by "default" from the storage handler. If the entity is translated, check if any of the translations are published.

Parameters

ContentEntityInterface $entity

The entity being saved.

Return Value

bool

TRUE if the default revision is published. FALSE otherwise.

WorkflowInterface|null getWorkflowForEntity(ContentEntityInterface $entity)

Gets the workflow for the given content entity.

Parameters

ContentEntityInterface $entity

The content entity to get the workflow for.

Return Value

WorkflowInterface|null

The workflow entity. NULL if there is no workflow.

WorkflowInterface|null getWorkflowForEntityTypeAndBundle(string $entity_type_id, string $bundle_id)

Gets the workflow for the given entity type and bundle.

Parameters

string $entity_type_id

The entity type ID.

string $bundle_id

The entity bundle ID.

Return Value

WorkflowInterface|null

The associated workflow. NULL if there is no workflow.

array getUnsupportedFeatures(EntityTypeInterface $entity_type)

Gets unsupported features for a given entity type.

Parameters

EntityTypeInterface $entity_type

The entity type to get the unsupported features for.

Return Value

array

An array of unsupported features for this entity type.

ContentModerationState getOriginalState(ContentEntityInterface $entity)

Gets the original or initial state of the given entity.

When a state is being validated, the original state is used to validate that a valid transition exists for target state and the user has access to the transition between those two states. If the entity has been moderated before, we can load the original unmodified revision and translation for this state.

If the entity is new we need to load the initial state from the workflow. Even if a value was assigned to the moderation_state field, the initial state is used to compute an appropriate transition for the purposes of validation.

Parameters

ContentEntityInterface $entity

The content entity to get the workflow for.

Return Value

ContentModerationState

The original or default moderation state.

protected bool isFirstTimeModeration(ContentEntityInterface $entity)

Determines if this entity is being moderated for the first time.

If the previous version of the entity has no moderation state, we assume that means it predates the presence of moderation states.

Parameters

ContentEntityInterface $entity

The entity being moderated.

Return Value

bool

TRUE if this is the entity's first time being moderated, FALSE otherwise.