foreach($stateMachineMigration->getTransitions()as$transition){ if(!\array_key_exists('actionName', $transition)){ thrownew \RuntimeException('Please provide "actionName" to all transitions'); }
// Verify that we are still on the workflow edit page.
$this->assertSession()->addressEquals('admin/config/workflow/workflows/manage/test');
// Ensure that a delete link for the published state exists before deleting
// the draft state.
$published_delete_link = Url::fromRoute('entity.workflow.delete_state_form', [
$this->singlePlace = $singlePlace; }
/**
* @return void
*/ publicfunctionvalidate(Definition $definition, string $name) { // Make sure all transitions for one place has unique name.
$places = array_fill_keys($definition->getPlaces(), []); foreach($definition->getTransitions()as$transition){ foreach($transition->getFroms()as$from){ if(\in_array($transition->getName(), $places[$from])){ thrownewInvalidDefinitionException(sprintf('All transitions for a place must have an unique name. Multiple transitions named "%s" where found for place "%s" in workflow "%s".', $transition->getName(), $from, $name)); } $places[$from][] = $transition->getName(); } }
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/ classStateMachineValidatorimplements DefinitionValidatorInterface { /**
* @return void
*/ publicfunctionvalidate(Definition $definition, string $name) { $transitionFromNames = []; foreach($definition->getTransitions()as$transition){ // Make sure that each transition has exactly one TO
if(1 !== \count($transition->getTos())){ thrownewInvalidDefinitionException(sprintf('A transition in StateMachine can only have one output. But the transition "%s" in StateMachine "%s" has %d outputs.', $transition->getName(), $name, \count($transition->getTos()))); }
// Make sure that each transition has exactly one FROM
$froms = $transition->getFroms(); if(1 !== \count($froms)){ thrownewInvalidDefinitionException(sprintf('A transition in StateMachine can only have one input. But the transition "%s" in StateMachine "%s" has %d inputs.', $transition->getName(), $name, \count($froms))); }
/**
* Returns an array of transition permissions.
*
* @return array
* The transition permissions.
*/ publicfunctiontransitionPermissions(){ $permissions = []; /** @var \Drupal\workflows\WorkflowInterface $workflow */ foreach(Workflow::loadMultipleByType('content_moderation')as$workflow){ foreach($workflow->getTypePlugin()->getTransitions()as$transition){ $permissions['use ' . $workflow->id() . ' transition ' . $transition->id()] = [ 'title' => $this->t('%workflow workflow: Use %transition transition.', [ '%workflow' => $workflow->label(), '%transition' => $transition->label(), ]), 'description' => $this->formatPlural( count($transition->from()), 'Move content from %from state to %to state.', 'Move content from %from states to %to state.', [ '%from' => implode(', ', array_map([State::class, 'labelCallback'], $transition->from())), '%to' => $transition->to()->label(), ]