maestro-3.0.1-rc2/modules/maestro_utilities/maestro_utilities.module

modules/maestro_utilities/maestro_utilities.module
<?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'),
    'maestro_show_test_message_form' => t('Simple test interactive task that shows the task title as the 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;
}

/**
 * Basic Interactive Function to show a message
 * that includes the Task Title or Name
 *
 * @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_test_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);
  $queueRecord = MaestroEngine::getQueueEntryById($queueID);
  $task_label = $queueRecord->task_label->getString();
  $message = 'Demonstration of Interactive Task: ' . $task_label;

  $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;
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc