Skip to content

Commit e5b6b85

Browse files
committed
Cleaned up os2forms_maestro_webform
1 parent f1484c2 commit e5b6b85

File tree

3 files changed

+101
-348
lines changed

3 files changed

+101
-348
lines changed

web/modules/custom/os2forms_maestro_webform/os2forms_maestro_webform.info.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ description: Stubbed-out code for OS2Forms
33
core_version_requirement: ^9.4 || ^10
44
package: OS2Forms
55
type: module
6-
scripts:
6+
scripts:
Lines changed: 100 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,148 @@
11
<?php
22

3+
/**
4+
* @file
5+
* Module file for os2forms_maestro_webform.
6+
*/
7+
38
use Drupal\Core\Form\FormStateInterface;
49
use Drupal\maestro\Engine\MaestroEngine;
510

6-
/*
7-
* Stub-code for OS2Forms to use for anonymous form detection and processing.
8-
* This module includes a direct copy of the Webform Inherit Task Type. Do not copy that over!
9-
*/
10-
1111
/**
1212
* Implements hook_maestro_zero_user_notification().
1313
*/
1414
function os2forms_maestro_webform_maestro_zero_user_notification($templateMachineName, $taskMachineName, $queueID, $notificationType) {
15-
// This only fires with a ZERO user-count on notifications. Use this as you see fit.
16-
17-
if($notificationType == 'assignment') {
15+
// This only fires with a ZERO user-count on notifications. Use this as you
16+
// see fit.
17+
if ($notificationType == 'assignment') {
1818
$templateTask = MaestroEngine::getTemplateTaskByID($templateMachineName, $taskMachineName);
19-
if($templateTask && $templateTask['tasktype'] == 'MaestroWebformInherit') {
20-
//This is very rigid in only detecting the Maestro Webform Inherit task.
21-
//You will do an API call here.
2219

23-
//see os2forms_maestro_webform_mail_alter() for example on detecting role assignment for citizen,
24-
//and the ability to read the webform for submission results (to get email addresses etc.)
20+
if ($templateTask && $templateTask['tasktype'] == 'MaestroWebformInherit') {
21+
// This is very rigid in only detecting the Maestro Webform Inherit task.
22+
// You will do an API call here.
23+
// See os2forms_maestro_webform_mail_alter() for example on detecting role
24+
// assignment for citizen, and the ability to read the webform for
25+
// submission results (to get email addresses etc.)
2526
}
2627
}
27-
2828
}
2929

30-
31-
/**
32-
* Implements hook_mail_alter().
33-
*/
34-
function os2forms_maestro_webform_mail_alter(&$message) {
30+
/**
31+
* Implements hook_mail_alter().
32+
*/
33+
function os2forms_maestro_webform_mail_alter(&$message) {
3534
if ($message['id'] == 'maestro_assignment_notification') {
36-
if(array_key_exists('queueID', $message['params'])) {
35+
if (array_key_exists('queueID', $message['params'])) {
3736
$queueID = intval($message['params']['queueID']);
3837
$templateTask = MaestroEngine::getTemplateTaskByQueueID($queueID);
3938

40-
//This is very rigid. This only looks for your Webform Inherit task type right now.
41-
//This should probably be offloaded to some kind of mechanism to detect that
42-
//an outgoing email needs to be sent via your API. Perhaps an additional
43-
//field/checkbox on the tasks that allows you to signify this is an anonymous task?
44-
if($templateTask && $templateTask['tasktype'] == 'MaestroWebformInherit') {
45-
//We should check if this task has an assignment that is sent to the anonymous Citizen role
39+
// This is very rigid. This only looks for your Webform Inherit task type
40+
// right now.
41+
// This should probably be offloaded to some kind of mechanism to detect
42+
// that an outgoing email needs to be sent via your API. Perhaps an
43+
// additional field/checkbox on the tasks that allows you to signify this
44+
// is an anonymous task?
45+
if ($templateTask && $templateTask['tasktype'] == 'MaestroWebformInherit') {
46+
// We should check if this task has an assignment that is sent to the
47+
// anonymous Citizen role.
4648
$assignments = explode(',', $templateTask['assigned']);
47-
if(is_array($assignments)) {
48-
foreach($assignments as $assignment) {
49-
if($assignment == 'role:fixed:citizen') { //Very rigid for this example.
49+
if (is_array($assignments)) {
50+
foreach ($assignments as $assignment) {
51+
// Very rigid for this example.
52+
if ($assignment == 'role:fixed:citizen') {
5053
$processID = MaestroEngine::getProcessIdFromQueueId($queueID);
5154

52-
//This is our use case. We found the Citizen role
53-
//You will fill in the blanks here to send out a proper
54-
//email notification through your government-based mailer
55-
56-
//TODO: Create outgoing email notification via API
57-
//TODO: Think of a way to get the generic information of WHO to send this to from the webform.
55+
// This is our use case. We found the Citizen role
56+
// You will fill in the blanks here to send out a proper
57+
// email notification through your government-based mailer.
58+
// @todo Create outgoing email notification via API
59+
// @todo Think of a way to get the generic information of WHO to send this to from the webform.
5860
$entityIdentifiers = MaestroEngine::getAllEntityIdentifiersForProcess($processID);
59-
//$entityIdentifiers will be an array of arrays, keyed with the entity's unique identifier
60-
61-
//For example: $entityIdentifiers['submission'] looks like this:
62-
/*
63-
submission:
64-
unique_id: "submission"
65-
entity_type: "webform_submission"
66-
bundle: "internship_1_student"
67-
entity_id: "11"
68-
*/
69-
//
70-
71-
//You will probably want to use $templateTask to detect the configuraton of THIS task.
72-
//That is: you will use something like $templateTask['data']['inherit_webform_unique_id'] to
73-
//use the configured unique ID against the entityIdentifiers from above to fetch off
74-
//any of the pertinent information.
75-
76-
77-
//TODO: Again, need a way to validate, verify and make this generic.
78-
79-
61+
// $entityIdentifiers will be an array of arrays, keyed with the
62+
// entity's unique identifier
63+
// For example: $entityIdentifiers['submission'] looks like this:
64+
/*
65+
submission:
66+
unique_id: "submission"
67+
entity_type: "webform_submission"
68+
bundle: "internship_1_student"
69+
entity_id: "11"
70+
*/
71+
72+
// You will probably want to use $templateTask to detect the
73+
// configuraton of THIS task.
74+
// That is: you will use something like
75+
// $templateTask['data']['inherit_webform_unique_id'] to use the
76+
// configured unique ID against the entityIdentifiers from above
77+
// to fetch off any of the pertinent information.
78+
// @todo Again, need a way to validate, verify and make this
79+
// generic.
80+
if ($entityIdentifiers) {
81+
// …
82+
}
8083
}
8184
}
8285
}
8386
}
8487
}
8588
}
86-
}
87-
89+
}
8890

89-
/**
91+
/**
9092
* Implements hook_form_alter().
93+
*
94+
* Your implementation is a direct copy from Maestro Webform's form alter. So is
95+
* this one. Your implementation has no special save handler and offloads to
96+
* Maestro's. Maestro's now has a special handling mechanism to try to correlate
97+
* the token to the queue and the form submission values. Maestro also detects
98+
* if the webform being altered is a maestro webform task type (inherited too)
99+
*
100+
* @todo architecture question
101+
* should you not be validating the company somehow? Same email address on both
102+
* forms?
91103
*/
92-
93-
//Your implementation is a direct copy from Maestro Webform's form alter.
94-
//So is this one. Your implementation has no special save handler and offloads
95-
//to Maestro's. Maestro's now has a special handling mechanism to try to correlate the
96-
//token to the queue and the form submission values.
97-
//Maestro also detects if the webform being altered is a maestro webform task type (inherited too)
98-
99-
//TODO: architecture question
100-
//should you not be validating the company somehow? Same email address on both forms?
101-
102104
function os2forms_maestro_webform_form_alter(&$form, FormStateInterface $form_state, $form_id) {
103105
maestro_webform_form_alter($form, $form_state, $form_id);
104106

105-
//add your own submit handler for validation here?
106-
107+
// Add your own submit handler for validation here?
107108
}
108109

109-
110-
/*
110+
/**
111111
* Implements hook_maestro_can_user_execute_task_alter().
112-
* For OS2Forms, you may have a consistent assignment to an "anonymous" user via a role.
113-
* Use the QueueID and userID to drill into the task and alter the returnValue to TRUE
114-
* if this is a user that should be looking at this task.
115-
* You can make this as complex as you'd like it to be, checking things like sessions,
116-
* login tokens, email addresses etc.
112+
*
113+
* For OS2Forms, you may have a consistent assignment to an "anonymous" user via
114+
* a role. Use the QueueID and userID to drill into the task and alter the
115+
* returnValue to TRUE if this is a user that should be looking at this task.
116+
*
117+
* You can make this as complex as you'd like it to be, checking things like
118+
* sessions, login tokens, email addresses etc.
117119
*/
118120
function os2forms_maestro_webform_maestro_can_user_execute_task_alter(&$returnValue, $queueID, $userID) {
119121

120-
// Check if this is an anonymous user and we've been barred access already
121-
if($userID == 0 && $returnValue === FALSE) {
122-
// Load the template task and we'll determine if this has our "special" assignment
123-
// to a known "anonymous" role.
122+
// Check if this is an anonymous user and we've been barred access already.
123+
if ($userID == 0 && $returnValue === FALSE) {
124+
// Load the template task and we'll determine if this has our "special"
125+
// assignment to a known "anonymous" role.
124126
$templateTask = MaestroEngine::getTemplateTaskByQueueID($queueID);
125127
$assignments = explode(',', $templateTask['assigned']);
126128

127-
// DEV NOTE!!!! We do NOTHING to ensure that this is a specific task type or even that this
128-
// is in our desired workflows. This routine will run for each and every task execution test
129-
// and only if we're anonymous. This should be streamlined and tightened up to check for
130-
// more specific task types or process types... perhaps...
131-
132-
// In our very specific use case, we are assigning to a fixed role of Citizen.
133-
// This could be a task config option to denote that regardless of what's in the assignment,
134-
// we validate this task as executable one way or another.
135-
136-
//TODO: Add in your own validation routines
137-
138-
foreach($assignments as $assignment) {
139-
if($assignment == 'role:fixed:citizen') {
140-
//This is our use case. Very rigid for now for prototyping/demo purposes.
129+
// DEV NOTE!!!! We do NOTHING to ensure that this is a specific task type or
130+
// even that this is in our desired workflows. This routine will run for
131+
// each and every task execution test and only if we're anonymous. This
132+
// should be streamlined and tightened up to check for more specific task
133+
// types or process types... perhaps...
134+
// In our very specific use case, we are assigning to a fixed role of
135+
// Citizen.
136+
// This could be a task config option to denote that regardless of what's in
137+
// the assignment, we validate this task as executable one way or another.
138+
// @todo Add in your own validation routines
139+
foreach ($assignments as $assignment) {
140+
if ($assignment == 'role:fixed:citizen') {
141+
// This is our use case. Very rigid for now for prototyping/demo
142+
// purposes.
141143
$returnValue = TRUE;
142144
}
143145
}
144146
}
145-
146-
147-
}
147+
148+
}

0 commit comments

Comments
 (0)