You are here

function maestro_form_approval_example_form_alter in Maestro 8.2

Same name and namespace in other branches
  1. 3.x modules/examples/maestro_form_approval_example/maestro_form_approval_example.module \maestro_form_approval_example_form_alter()

Implements hook_form_alter().

File

modules/examples/maestro_form_approval_example/maestro_form_approval_example.module, line 28
You need this if you want to simply use MaestroEngine in code calls as we do.

Code

function maestro_form_approval_example_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  // Just a quick and easy way to override the submit button for our example.
  // for regular users, don't give them the option to unpublish etc.
  // as per the note in maestro.module, this IF statement should also test to see if
  // the content type we're editing is attached to a process, regardless if the maestro and
  // queueid keys exist in the URL.
  // for the purposes of this demo, testing to see if the query string has the 2 keys we need
  // is sufficient.
  $storage = $form_state
    ->getStorage();
  if (array_key_exists('form_display', $storage)) {
    $thisForm = $storage['form_display']
      ->get('bundle');
  }
  else {
    $thisForm = NULL;
  }
  $queueID = intval(\Drupal::request()->query
    ->get('queueid', 0));
  $isMaestro = intval(\Drupal::request()->query
    ->get('maestro', 0));
  $templateTask = MaestroEngine::getTemplateTaskByQueueID($queueID);
  if ($isMaestro > 0 && $queueID > 0 && $templateTask['tasktype'] == 'MaestroContentType' && MaestroEngine::canUserExecuteTask($queueID, \Drupal::currentUser()
    ->id()) && $templateTask['data']['content_type'] == $thisForm) {
    $form['actions']['submit']['#value'] = t('Submit Request');
    $form['actions']['publish']['#value'] = t('Submit Request');
    $form['actions']['unpublish']['#value'] = t('Submit Request');
  }
}