class ContentModeration extends WorkflowTypeBase implements ContentModerationInterface, ContainerFactoryPluginInterface (View source)

Attaches workflows to content entity types and their bundles.

Traits

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

Provides a trait with typical behavior for plugins which have forms.

Constants

DERIVATIVE_SEPARATOR

A string which is used to separate base plugin IDs from the derivative ID.

VALID_ID_REGEX

A regex for matching a valid state/transition machine name.

Properties

protected string $pluginId

The plugin_id.

from  PluginBase
protected array $pluginDefinition

The plugin implementation definition.

from  PluginBase
protected array $configuration

Configuration information passed into the plugin.

from  PluginBase
protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

protected EntityTypeBundleInfoInterface $entityTypeBundleInfo

The entity type bundle info service.

protected ModerationInformationInterface $moderationInfo

The moderation information service.

Methods

__construct(array $configuration, string $plugin_id, mixed $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, ModerationInformationInterface $moderation_info)

Constructs a ContentModeration object.

string
getPluginId()

Gets the plugin_id of the plugin instance.

string
getBaseId()

Gets the base_plugin_id of the plugin instance.

string|null
getDerivativeId()

Gets the derivative_id of the plugin instance.

array
getPluginDefinition()

Gets the definition of the plugin implementation.

bool
isConfigurable()

Determines if the plugin is configurable.

getFormClass($operation)

{@inheritdoc}

hasFormClass($operation)

{@inheritdoc}

string
label()

Gets the label for the workflow type.

bool
workflowHasData(WorkflowInterface $workflow)

Determines if the workflow is being has data associated with it.

bool
workflowStateHasData(WorkflowInterface $workflow, StateInterface $state)

Determines if the workflow state has data associated with it.

array
getConfiguration()

Gets this plugin's configuration.

setConfiguration(array $configuration)

Sets the configuration for this plugin instance.

string[]
getRequiredStates()

Gets the required states of workflow type.

array
defaultConfiguration()

Gets default configuration for this plugin.

array
calculateDependencies()

Calculates dependencies for the configured plugin.

bool
onDependencyRemoval(array $dependencies)

Informs the plugin that a dependency of the workflow will be deleted.

getInitialState($entity = NULL)

Gets the initial state for the workflow.

$this
addState(string $state_id, string $label)

Adds a state to the workflow.

bool
hasState(string $state_id)

Determines if the workflow has a state with the provided ID.

getStates(string[] $state_ids = NULL)

Gets state objects for the provided state IDs.

getState(string $state_id)

Gets a workflow state.

$this
setStateLabel(string $state_id, string $label)

Sets a state's label.

$this
setStateWeight(string $state_id, int $weight)

Sets a state's weight value.

$this
deleteState(string $state_id)

Deletes a state from the workflow.

$this
addTransition($transition_id, string $label, array $from_state_ids, string $to_state_id)

Adds a transition to the workflow.

getTransitions(array $transition_ids = NULL)

Gets transition objects for the provided transition IDs.

labelWeightMultisort(StateInterface[]|TransitionInterface[] $objects)

Sort states or transitions by weight, label, and key.

getTransition(string $transition_id)

Gets a transition object for the provided transition ID.

bool
hasTransition(string $transition_id)

Determines if a transition exists.

array
getTransitionsForState($state_id, string $direction = TransitionInterface::DIRECTION_FROM)

Gets the transition IDs for a state for the provided direction.

getTransitionFromStateToState(string $from_state_id, string $to_state_id)

Gets a transition from state to state.

bool
hasTransitionFromStateToState(string $from_state_id, string $to_state_id)

Determines if a transition from state to state exists.

string|null
getTransitionIdFromStateToState(string $from_state_id, string $to_state_id)

Gets the transition ID from state to state.

$this
setTransitionLabel(string $transition_id, string $label)

Sets a transition's label.

$this
setTransitionWeight(string $transition_id, int $weight)

Sets a transition's weight.

$this
setTransitionFromStates(string $transition_id, array $from_state_ids)

Sets a transition's from states.

$this
deleteTransition(string $transition_id)

Deletes a transition.

int
getNextWeight(array $items)

Gets the weight for a new state or transition.

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.

create(ContainerInterface $container, array $configuration, string $plugin_id, mixed $plugin_definition)

Creates an instance of the plugin.

string[]
getEntityTypes()

Gets the entity types the workflow is applied to.

string[]
getBundlesForEntityType(string $entity_type_id)

Gets any bundles the workflow is applied to for the given entity type.

bool
appliesToEntityTypeAndBundle(string $entity_type_id, string $bundle_id)

Checks if the workflow applies to the supplied entity type and bundle.

removeEntityTypeAndBundle(string $entity_type_id, string $bundle_id)

Removes an entity type ID / bundle ID from the workflow.

addEntityTypeAndBundle(string $entity_type_id, string $bundle_id)

Add an entity type ID / bundle ID to the workflow.

Details

__construct(array $configuration, string $plugin_id, mixed $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, ModerationInformationInterface $moderation_info)

Constructs a ContentModeration object.

Parameters

array $configuration

A configuration array containing information about the plugin instance.

string $plugin_id

The plugin_id for the plugin instance.

mixed $plugin_definition

The plugin implementation definition.

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

EntityTypeBundleInfoInterface $entity_type_bundle_info
ModerationInformationInterface $moderation_info

Moderation information service.

string getPluginId()

Gets the plugin_id of the plugin instance.

Return Value

string

The plugin_id of the plugin instance.

string getBaseId()

Gets the base_plugin_id of the plugin instance.

Return Value

string

The base_plugin_id of the plugin instance.

string|null getDerivativeId()

Gets the derivative_id of the plugin instance.

Return Value

string|null

The derivative_id of the plugin instance NULL otherwise.

array getPluginDefinition()

Gets the definition of the plugin implementation.

Return Value

array

The plugin definition, as returned by the discovery object used by the plugin manager.

bool isConfigurable()

Determines if the plugin is configurable.

Return Value

bool

A boolean indicating whether the plugin is configurable.

getFormClass($operation)

{@inheritdoc}

Parameters

$operation

hasFormClass($operation)

{@inheritdoc}

Parameters

$operation

string label()

Gets the label for the workflow type.

Return Value

string

The workflow type label.

bool workflowHasData(WorkflowInterface $workflow)

Determines if the workflow is being has data associated with it.

Parameters

WorkflowInterface $workflow

The workflow to check.

Return Value

bool

TRUE if the workflow is being used, FALSE if not.

bool workflowStateHasData(WorkflowInterface $workflow, StateInterface $state)

Determines if the workflow state has data associated with it.

Parameters

WorkflowInterface $workflow

The workflow to check.

StateInterface $state

The workflow state to check.

Return Value

bool

TRUE if the workflow state is being used, FALSE if not.

array getConfiguration()

Gets this plugin's configuration.

Return Value

array

An array of this plugin's configuration.

setConfiguration(array $configuration)

Sets the configuration for this plugin instance.

Parameters

array $configuration

An associative array containing the plugin's configuration.

string[] getRequiredStates()

Gets the required states of workflow type.

This is usually specified in the workflow type annotation.

Return Value

string[]

The required states.

array defaultConfiguration()

Gets default configuration for this plugin.

Return Value

array

An associative array with the default configuration.

array calculateDependencies()

Calculates dependencies for the configured plugin.

Dependencies are saved in the plugin's configuration entity and are used to determine configuration synchronization order. For example, if the plugin integrates with specific user roles, this method should return an array of dependencies listing the specified roles.

Return Value

array

An array of dependencies grouped by type (config, content, module, theme). For example: @code array( 'config' => array('user.role.anonymous', 'user.role.authenticated'), 'content' => array('node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'), 'module' => array('node', 'user'), 'theme' => array('seven'), ); @endcode

bool onDependencyRemoval(array $dependencies)

Informs the plugin that a dependency of the workflow will be deleted.

Parameters

array $dependencies

An array of dependencies that will be deleted keyed by dependency type.

Return Value

bool

TRUE if the workflow settings have been changed, FALSE if not.

StateInterface getInitialState($entity = NULL)

Gets the initial state for the workflow.

Parameters

$entity

Return Value

StateInterface

The initial state.

$this addState(string $state_id, string $label)

Adds a state to the workflow.

Parameters

string $state_id

The state's ID.

string $label

The state's label.

Return Value

$this

Exceptions

InvalidArgumentException

bool hasState(string $state_id)

Determines if the workflow has a state with the provided ID.

Parameters

string $state_id

The state's ID.

Return Value

bool

TRUE if the workflow has a state with the provided ID, FALSE if not.

StateInterface[] getStates(string[] $state_ids = NULL)

Gets state objects for the provided state IDs.

Parameters

string[] $state_ids

A list of state IDs to get. If NULL then all states will be returned.

Return Value

StateInterface[]

An array of workflow states, keyed by state IDs.

Exceptions

InvalidArgumentException

StateInterface getState(string $state_id)

Gets a workflow state.

Parameters

string $state_id

The state's ID.

Return Value

StateInterface

The workflow state.

Exceptions

InvalidArgumentException

$this setStateLabel(string $state_id, string $label)

Sets a state's label.

Parameters

string $state_id

The state ID to set the label for.

string $label

The state's label.

Return Value

$this

$this setStateWeight(string $state_id, int $weight)

Sets a state's weight value.

Parameters

string $state_id

The state ID to set the weight for.

int $weight

The state's weight.

Return Value

$this

$this deleteState(string $state_id)

Deletes a state from the workflow.

Parameters

string $state_id

The state ID to delete.

Return Value

$this

The workflow type plugin.

Exceptions

InvalidArgumentException

$this addTransition($transition_id, string $label, array $from_state_ids, string $to_state_id)

Adds a transition to the workflow.

Parameters

$transition_id
string $label

The transition's label.

array $from_state_ids

The state IDs to transition from.

string $to_state_id

The state ID to transition to.

Return Value

$this

Exceptions

InvalidArgumentException

TransitionInterface[] getTransitions(array $transition_ids = NULL)

Gets transition objects for the provided transition IDs.

Parameters

array $transition_ids

A list of transition IDs to get. If NULL then all transitions will be returned.

Return Value

TransitionInterface[]

An array of transition objects.

Exceptions

InvalidArgumentException

static protected StateInterface[]|TransitionInterface[] labelWeightMultisort(StateInterface[]|TransitionInterface[] $objects)

Sort states or transitions by weight, label, and key.

Parameters

StateInterface[]|TransitionInterface[] $objects

An array of state or transition objects to multi-sort, keyed by the state or transition ID.

Return Value

StateInterface[]|TransitionInterface[]

An array of sorted transitions or states, keyed by the state or transition ID.

TransitionInterface getTransition(string $transition_id)

Gets a transition object for the provided transition ID.

Parameters

string $transition_id

A transition ID.

Return Value

TransitionInterface

The transition.

Exceptions

InvalidArgumentException

bool hasTransition(string $transition_id)

Determines if a transition exists.

Parameters

string $transition_id

The transition ID.

Return Value

bool

TRUE if the transition exists, FALSE if not.

array getTransitionsForState($state_id, string $direction = TransitionInterface::DIRECTION_FROM)

Gets the transition IDs for a state for the provided direction.

Parameters

$state_id

The state to get transitions for.

string $direction

(optional) The direction of the transition, defaults to TransitionInterface::DIRECTION_FROM. Possible values are: TransitionInterface::DIRECTION_FROM or TransitionInterface::DIRECTION_TO.

Return Value

array

The transition IDs for a state for the provided direction.

TransitionInterface getTransitionFromStateToState(string $from_state_id, string $to_state_id)

Gets a transition from state to state.

Parameters

string $from_state_id

The state ID to transition from.

string $to_state_id

The state ID to transition to.

Return Value

TransitionInterface

The transitions.

Exceptions

InvalidArgumentException

bool hasTransitionFromStateToState(string $from_state_id, string $to_state_id)

Determines if a transition from state to state exists.

Parameters

string $from_state_id

The state ID to transition from.

string $to_state_id

The state ID to transition to.

Return Value

bool

TRUE if the transition exists, FALSE if not.

protected string|null getTransitionIdFromStateToState(string $from_state_id, string $to_state_id)

Gets the transition ID from state to state.

Parameters

string $from_state_id

The state ID to transition from.

string $to_state_id

The state ID to transition to.

Return Value

string|null

The transition ID, or NULL if no transition exists.

$this setTransitionLabel(string $transition_id, string $label)

Sets a transition's label.

Parameters

string $transition_id

The transition ID.

string $label

The transition's label.

Return Value

$this

Exceptions

InvalidArgumentException

$this setTransitionWeight(string $transition_id, int $weight)

Sets a transition's weight.

Parameters

string $transition_id

The transition ID.

int $weight

The transition's weight.

Return Value

$this

Exceptions

InvalidArgumentException

$this setTransitionFromStates(string $transition_id, array $from_state_ids)

Sets a transition's from states.

Parameters

string $transition_id

The transition ID.

array $from_state_ids

The state IDs to transition from.

Return Value

$this

Exceptions

InvalidArgumentException

$this deleteTransition(string $transition_id)

Deletes a transition.

Parameters

string $transition_id

The transition ID.

Return Value

$this

Exceptions

InvalidArgumentException

protected int getNextWeight(array $items)

Gets the weight for a new state or transition.

Parameters

array $items

An array of states or transitions information where each item has a 'weight' key with a numeric value.

Return Value

int

The weight for a new item in the array so that it has the highest weight.

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 ContainerFactoryPluginInterface create(ContainerInterface $container, array $configuration, string $plugin_id, mixed $plugin_definition)

Creates an instance of the plugin.

Parameters

ContainerInterface $container

The container to pull out services used in the plugin.

array $configuration

A configuration array containing information about the plugin instance.

string $plugin_id

The plugin ID for the plugin instance.

mixed $plugin_definition

The plugin implementation definition.

Return Value

ContainerFactoryPluginInterface

Returns an instance of this plugin.

string[] getEntityTypes()

Gets the entity types the workflow is applied to.

Return Value

string[]

The entity types the workflow is applied to.

string[] getBundlesForEntityType(string $entity_type_id)

Gets any bundles the workflow is applied to for the given entity type.

Parameters

string $entity_type_id

The entity type ID to get the bundles for.

Return Value

string[]

The bundles of the entity type the workflow is applied to or an empty array if the entity type is not applied to the workflow.

bool appliesToEntityTypeAndBundle(string $entity_type_id, string $bundle_id)

Checks if the workflow applies to the supplied entity type and bundle.

Parameters

string $entity_type_id

The entity type ID to check.

string $bundle_id

The bundle ID to check.

Return Value

bool

TRUE if the workflow applies to the supplied entity type ID and bundle ID. FALSE if not.

removeEntityTypeAndBundle(string $entity_type_id, string $bundle_id)

Removes an entity type ID / bundle ID from the workflow.

Parameters

string $entity_type_id

The entity type ID to remove.

string $bundle_id

The bundle ID to remove.

addEntityTypeAndBundle(string $entity_type_id, string $bundle_id)

Add an entity type ID / bundle ID to the workflow.

Parameters

string $entity_type_id

The entity type ID to add. It is responsibility of the caller to provide a valid entity type ID.

string $bundle_id

The bundle ID to add. It is responsibility of the caller to provide a valid bundle ID.