You are here

function maestro_form_approval_example_maestro_task_console_alter_execution_link 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_maestro_task_console_alter_execution_link()

Implements hook_maestro_task_console_alter_execution_link().

File

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

Code

function maestro_form_approval_example_maestro_task_console_alter_execution_link(&$existing_execution_form_elements, $templateTask, $queueRecord, $templateMachineName) {

  /*
   * Example of how you can add your own custom links in the actions/operations task console or alter the action form completely for this task.
   * It's a drupal form and you are passed in $form as rendered by the the taskconsole for this task.
   *
   * By Default, the drupal console will use the FORM API Element type 'operations' which is a special use-case of the dropbutton eleement
   * that can have multiple links or actions that appear as part of the button.
   * https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21Element%21Dropbutton.php/class/Dropbutton/8.2.x
   *
   *
   * For this specific example use: There's already a link to view the report in the approval form,
   * We will show how to provide it as an extra action to the dropButton links.
   *
   * If one did not want to use the dropButton 'operations' element, then you fully alter it here and change the way the actions appear
   * in the task console.
   */

  /*
   * We're simply picking off the entity in our process variable.
   * see the maestro_form_approval_example_manager_approval_form function above for more explanation.
   *
   * First, we should check if this is the workflow or template that we want to change
   * the active task action for, else we will affect all tasks.
   */
  if ($templateMachineName == 'form_approval_flow' && $templateTask['id'] == 'manager_approval') {
    $processID = $queueRecord->process_id
      ->getString();
    $entityID = MaestroEngine::getEntityIdentiferByUniqueID($processID, 'request');
    $url = Url::fromUserInput('/node/' . $entityID, [
      'attributes' => [
        'target' => '_new',
      ],
    ]);

    /*
     * We are appending our link to data element['#links']
     */
    $existing_execution_form_elements['data']['#links']['custom_link'] = [
      'title' => t('View Request in separate page'),
      'url' => $url,
    ];
  }
}