function maestro_form_approval_example_manager_approval_form in Maestro 8.2
Same name and namespace in other branches
- 3.x modules/examples/maestro_form_approval_example/maestro_form_approval_example.module \maestro_form_approval_example_manager_approval_form()
The manager approval form used in the workflow.
Parameters
array $form: The array that contains the form.
int $queueID: The queueID from Maestro.
object $obj: References the calling object.
1 string reference to 'maestro_form_approval_example_manager_approval_form'
- maestro.maestro_template.form_approval_flow.yml in modules/
examples/ maestro_form_approval_example/ config/ install/ maestro.maestro_template.form_approval_flow.yml - modules/examples/maestro_form_approval_example/config/install/maestro.maestro_template.form_approval_flow.yml
File
- modules/
examples/ maestro_form_approval_example/ maestro_form_approval_example.module, line 70 - You need this if you want to simply use MaestroEngine in code calls as we do.
Code
function maestro_form_approval_example_manager_approval_form(array &$form, $queueID, $obj) {
$form['queueID'] = [
'#type' => 'hidden',
'#title' => 'the queue ID in the event we need it in later processing',
'#default_value' => $queueID,
'#description' => 'queueID',
];
// Overriding the "Accept" default label with the "complete" text.
$form['actions']['submit']['#value'] = t('Accept Request');
// Adding our own reject button.
$form['actions']['reject'] = [
'#type' => 'submit',
'#value' => t('Reject and send back to Employee'),
'#ajax' => [
'callback' => [
$obj,
'completeForm',
],
'wrapper' => '',
],
];
// Change the title of the modal popup from the default bland Maestro title.
$form['#title'] = t('Review the Employee Request');
// We are going to give the user a link to the approval form here. We do this by loading the
// queue and fetching off the approval form and providing a link to it.
$processID = MaestroEngine::getProcessIdFromQueueId($queueID);
$entityID = MaestroEngine::getEntityIdentiferByUniqueID($processID, 'request');
// [0] is the unique key, [1] is the type, [2] is the node ID
$url = Url::fromUserInput('/node/' . $entityID, [
'attributes' => [
'target' => '_new',
],
]);
// Load the node.
$node = Node::load($entityID);
// Generate a view of the node.
$build = \Drupal::entityTypeManager()
->getViewBuilder('node')
->view($node, 'full');
// Attach the node to the form for viewing.
$form['node'] = $build;
// Wrapper to beautify it.
$form['node']['#prefix'] = '<div id="manager-approval-node">';
$form['node']['#suffix'] = '</div>';
// We throw this link in here ot show that you can still link directly to the node if you want.
$form['url'] = [
'#type' => 'link',
'#title' => t('(View Request in full page)'),
// Will open in new tab.
'#url' => $url,
'#target' => '_new',
'#suffix' => '<br><br>',
];
// Our own css for node form beautification.
$form['#attached']['library'][] = 'maestro_form_approval_example/maestro_approval_form_css';
return $form;
}