You are here

public function StateChange::change in Workbench Moderation Actions 8

Performs the moderation state change.

1 string reference to 'StateChange::change'
workbench_moderation_actions.routing.yml in ./workbench_moderation_actions.routing.yml
workbench_moderation_actions.routing.yml

File

src/Controller/StateChange.php, line 54

Class

StateChange
Performs the state change, if user has access to do it.

Namespace

Drupal\workbench_moderation_actions\Controller

Code

public function change($entity_type_id, $entity_id, $from, $to) {
  $latest_revision = $this->moderationInfo
    ->getLatestRevision($entity_type_id, $entity_id);
  $latest_revision
    ->get('moderation_state')->target_id = $to;
  $latest_revision
    ->save();
  $this
    ->messenger()
    ->addMessage($this
    ->t('%entity_label got changed from %from to %to', [
    '%entity_label' => $latest_revision
      ->label(),
    '%from' => ModerationState::load($from)
      ->label(),
    '%to' => ModerationState::load($to)
      ->label(),
  ]));
  return (new AjaxResponse())
    ->addCommand(new AjaxReloadCommand());
}