You are here

protected function MaestroRulesActionSpawnWorkflow::doExecute in Maestro 8.2

Same name and namespace in other branches
  1. 3.x src/Plugin/RulesAction/MaestroRulesActionSpawnWorkflow.php \Drupal\maestro\Plugin\RulesAction\MaestroRulesActionSpawnWorkflow::doExecute()

Spawns a workflow.

Parameters

string $template: The workflow template machine name you wish to spawn.

\Drupal\Core\Entity\EntityInterface $entity: The entity that is being saved.

File

src/Plugin/RulesAction/MaestroRulesActionSpawnWorkflow.php, line 40

Class

MaestroRulesActionSpawnWorkflow
Provides a 'Delete entity' action.

Namespace

Drupal\maestro\Plugin\RulesAction

Code

protected function doExecute($template = NULL, EntityInterface $entity = NULL) {
  if ($template !== NULL) {
    $engine = new MaestroEngine();
    $process_id = $engine
      ->newProcess($template);
    if ($process_id) {
      $entity_id = current($entity->nid
        ->getValue())['value'];
      $entity_bundle = current($entity->type
        ->getValue())['target_id'];
      MaestroEngine::createEntityIdentifier($process_id, 'node', $entity_bundle, 'rules_added_entity', $entity_id);
    }
    else {

      // Error condition.  The process was unable to be kicked off.
      drupal_set_message(t('Unable to begin workflow.  Please check with administrator for more information.'));
    }
  }
}