abstract class WorkflowTypeBase extends PluginBase implements WorkflowTypeInterface (View source)

A base class for Workflow type plugins.

Traits

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

Methods

__construct(array $configuration, string $plugin_id, mixed $plugin_definition)

Constructs a \Drupal\Component\Plugin\PluginBase 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()

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.

Details

__construct(array $configuration, string $plugin_id, mixed $plugin_definition)

Constructs a \Drupal\Component\Plugin\PluginBase 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.

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()

Gets the initial state for the workflow.

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.