You are here

public function KanbanWorkflowService::onEntityPresave in Content Planner 8

Acts upon a entity presave.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The current entity that is saved.

\Drupal\Core\Session\AccountInterface $user: The user that is related to the entity save.

See also

content_kanban_entity_presave()

File

modules/content_kanban/src/KanbanWorkflowService.php, line 62

Class

KanbanWorkflowService
Class KanbanWorkflowService.

Namespace

Drupal\content_kanban

Code

public function onEntityPresave(ContentEntityInterface $entity, AccountInterface $user) {

  // If the entity is moderated, meaning it belongs to a certain workflow.
  if ($this->moderationInformation
    ->isModeratedEntity($entity)) {
    $current_state = $this
      ->getCurrentStateId($entity);
    $prev_state = $this
      ->getPreviousWorkflowStateId($entity);
    if ($current_state && $prev_state) {

      // Generate name for entity.
      $name = $this
        ->t('Workflow State change on Entity')
        ->render();

      // Get workflow from moderated entity.
      $workflow = $this->moderationInformation
        ->getWorkflowForEntity($entity);

      // Create new log entity.
      $this->kanbanLogService
        ->createLogEntity($name, $user
        ->id(), $entity
        ->id(), $entity
        ->getEntityTypeId(), $workflow
        ->id(), $prev_state, $current_state);
    }
  }
}