You are here

maestro_utilities.module in Maestro 3.x

Same filename and directory in other branches
  1. 8.2 modules/maestro_utilities/maestro_utilities.module

You need this if you want to simply use MaestroEngine in code calls as we do.

File

modules/maestro_utilities/maestro_utilities.module
View source
<?php

/**
 * @file
 * You need this if you want to simply use MaestroEngine in code calls as we do.
 */
use Drupal\maestro\Engine\MaestroEngine;

/**
 * Implements hook_maestro_batch_handlers().
 *
 * Array of function names and help text that will be displayed
 * in the edit task form under the handler field.
 */
function maestro_utilities_maestro_batch_handlers() {
  return [
    'maestro_dummy_batch_function' => t('Dummy Batch Function. Does nothing. Simulates NOOP.'),
  ];
}

/**
 * Implements hook_maestro_interactive_handlers().
 *
 * Array of function names and help text that will be displayed
 * in the edit task form under the handler field.
 */
function maestro_utilities_maestro_interactive_handlers() {
  return [
    'maestro_accept_only_form' => t('Simple review task with a single Complete action button.'),
    'maestro_show_message_form' => t('Requires a process variable called message'),
  ];
}

/**
 * This is the Maestro Interactive Accept Only form.  This shows off how the interactive function task can fetch form elements
 * based on the handler field in the queue (set by the template)
 *
 * The interactive function engine UI task passes the queue ID to the form and the user is
 * responsible for managing the entire form at this point.
 *
 * @param array $form
 *   The form you will create with this function.
 * @param int $queueID
 *   The ID of the queue task ID you are executing.
 */
function maestro_accept_only_form(array &$form, $queueID = 0, $obj = NULL) {
  $form['queueID'] = [
    '#type' => 'hidden',
    '#title' => 'Hidden Queue ID',
    '#default_value' => $queueID,
    '#description' => 'queueID',
  ];
  $form['information_text'] = [
    '#plain_text' => t('Simple Interactive Task with a complete button.'),
    '#suffix' => '<br>',
  ];

  // Overriding the "Accept" default label with the "complete" text.
  $form['actions']['submit']['#value'] = t('Complete');
  return $form;
}

/**
 * This is the return from the simple accept Interactive function built in to Maestro.
 */
function maestro_accept_only_form_submit(array &$form, &$form_state, $queueID = 0) {

  // We don't need to do anything here, but here's an example of fetching off the form state's queue ID.
  $ourQueueID = $form_state
    ->getValue('queueID');
}

/**
 * Basic Interactive Function to show a message
 * Requires a process variable called 'message'.
 *
 * @param array $form
 *   The form you will create with this function.
 * @param int $queueID
 *   The ID of the queue task ID you are executing.
 */
function maestro_show_message_form(array &$form, $queueID = 0, $obj = NULL) {
  $form['queueID'] = [
    '#type' => 'hidden',
    '#title' => 'Hidden Queue ID',
    '#default_value' => $queueID,
    '#description' => 'queueID',
  ];
  $processID = MaestroEngine::getProcessIdFromQueueId($queueID);
  $message = MaestroEngine::getProcessVariable('message', $processID);
  if ($message === FALSE) {
    $message = 'No process variable called message defined for this workflow template';
  }
  $form['message'] = [
    '#plain_text' => $message,
    '#suffix' => '<br>',
  ];
  return $form;
}

/**
 * This is a dummy placeholder function to be used to do a batch function noop.
 *
 * @param int $processID
 *   The Maestro process ID.
 * @param int $queueID
 *   The Maestro queue ID.
 */
function maestro_dummy_batch_function($processID, $queueID) {

  /* Does nothing and immediately returns TRUE which tells
   * the engine that this task is complete.
   */
  return TRUE;
}

Functions

Namesort descending Description
maestro_accept_only_form This is the Maestro Interactive Accept Only form. This shows off how the interactive function task can fetch form elements based on the handler field in the queue (set by the template)
maestro_accept_only_form_submit This is the return from the simple accept Interactive function built in to Maestro.
maestro_dummy_batch_function This is a dummy placeholder function to be used to do a batch function noop.
maestro_show_message_form Basic Interactive Function to show a message Requires a process variable called 'message'.
maestro_utilities_maestro_batch_handlers Implements hook_maestro_batch_handlers().
maestro_utilities_maestro_interactive_handlers Implements hook_maestro_interactive_handlers().