You are here

public function MaestroWebformHandler::postSave in Maestro 3.x

Same name and namespace in other branches
  1. 8.2 modules/maestro_webform/src/Plugin/WebformHandler/MaestroWebformHandler.php \Drupal\maestro_webform\Plugin\WebformHandler\MaestroWebformHandler::postSave()

Acts on a saved webform submission before the insert or update hook is invoked.

Parameters

\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.

bool $update: TRUE if the entity has been updated, or FALSE if it has been inserted.

Overrides WebformHandlerBase::postSave

File

modules/maestro_webform/src/Plugin/WebformHandler/MaestroWebformHandler.php, line 205

Class

MaestroWebformHandler
Launches a Maestro workflow with a Webform submission.

Namespace

Drupal\maestro_webform\Plugin\WebformHandler

Code

public function postSave(WebformSubmissionInterface $webform_submission, $update = TRUE) {

  // This is where we launch our maestro workflow based on the configuration options for this webform.
  $maestro_skip = FALSE;
  if (isset($webform_submission->data['maestro_skip'])) {
    if ($webform_submission->data['maestro_skip']) {
      $maestro_skip = TRUE;
    }
  }
  else {
    $maestro_skip = FALSE;
  }

  // Only do this on NEW webforms & webforms that are not mid-workflow.
  if (!$update && !$maestro_skip) {
    $maestro = new MaestroEngine();
    $processID = $maestro
      ->newProcess($this->configuration['maestro_template']);
    if ($processID !== FALSE) {
      if ($this->configuration['maestro_message_success'] != '') {
        \Drupal::messenger()
          ->addStatus($this->configuration['maestro_message_success']);
      }

      // Set the entity identifier to attach this webform to the maestro workflow template that is put into production.
      if (!MaestroEngine::createEntityIdentifier($processID, $webform_submission
        ->getEntityTypeId(), $webform_submission
        ->bundle(), 'submission', $webform_submission
        ->id())) {
        \Drupal::messenger()
          ->addError($this->configuration['maestro_message_failure']);
      }
    }
    else {

      // Only show the message if our config says to do so.
      if ($this->configuration['maestro_message_failure'] != '') {
        \Drupal::messenger()
          ->addError($this->configuration['maestro_message_failure']);
      }
    }
  }
}