11<?php
22
3+ /**
4+ * @file
5+ * Install, update and uninstall functions for the os2forms_forloeb.
6+ */
7+
8+ use Drupal\Core\Session\AccountInterface;
9+ use Drupal\Core\Entity\EntityInterface;
310use Drupal\webform\WebformInterface;
411use Drupal\Core\Access\AccessResult;
512use Drupal\Core\Form\FormStateInterface;
@@ -10,12 +17,9 @@ use Drupal\webform\Entity\WebformSubmission;
1017use Drupal\user\Entity\User;
1118
1219/**
13- * @file
14- * Install, update and uninstall functions for the os2forms_forloeb_profile installation profile.
15- */
16-
17- /**
18- * Implements hook_maestro_interactive_handlers() for the return of an Array
20+ * Implements hook_maestro_interactive_handlers().
21+ *
22+ * Handler for the return of an Array
1923 * of function names and help text that will be displayed in the edit task
2024 * form under the handler field.
2125 */
@@ -35,70 +39,75 @@ function os2forms_forloeb_maestro_interactive_handlers() {
3539 * @param int $queueID
3640 * The queueID from Maestro.
3741 */
38- function os2forms_forloeb_workflow_maestro_reassign_form(&$form, $obj, $queueID = 0) {
42+ function os2forms_forloeb_workflow_maestro_reassign_form(array &$form, $obj, $queueID = 0) {
3943
40- $form['reviewer'] = array(
44+ $form['reviewer'] = [
4145 '#id' => 'select_assigned_user',
4246 '#type' => 'entity_autocomplete',
4347 '#target_type' => 'user',
4448 '#default_value' => '',
4549 '#selection_settings' => ['include_anonymous' => FALSE],
46- '#title' => t('Assign for Review to'),
47- ) ;
50+ '#title' => t('Assign for Review to'),
51+ ] ;
4852
49- $form['queueID'] = array(
53+ $form['queueID'] = [
5054 '#type' => 'hidden',
5155 '#title' => 'the queue ID in the event we need it in later processing',
5256 '#default_value' => $queueID,
5357 '#description' => ('queueID'),
54- ) ;
58+ ] ;
5559
56- //overriding the default label "complete"
60+ // Overriding the default label "complete".
5761 $form['actions']['submit']['#value'] = t('Assign');
5862
5963 return $form;
6064}
6165
62-
6366/**
64- * This is the submit handler for the Reassign for Approval form use in maestro workflows.
67+ * Submit handler for The Reassign for Approval form.
68+ *
69+ * This is the submit handler for the Reassign for Approval form
70+ * used in maestro workflows.
6571 */
6672function os2forms_forloeb_workflow_maestro_reassign_form_submit(&$form, &$form_state) {
6773
6874 $queueID = intval($form_state->getValue('queueID'));
6975 $processID = MaestroEngine::getProcessIdFromQueueId($queueID);
7076
71- //Who was selected? Load their username, which is the user attribute that Maestro assigns tasks by.
77+ // Who was selected? Load their username, which is the user attribute
78+ // that Maestro assigns tasks by.
7279 $reviewer_uid = $form_state->getValue('reviewer');
73- $reviewer = User::load($reviewer_uid); // pass your uid
80+ // Pass your uid.
81+ $reviewer = User::load($reviewer_uid);
7482 $reviewer_username = $reviewer->getAccountName();
7583
76- //add that user to our maestro process variable.
84+ // Add that user to our maestro process variable.
7785 MaestroEngine::setProcessVariable("assigned_to", $reviewer_username, $processID);
7886
79- //Provide some feedback
87+ // Provide some feedback.
8088 \Drupal::messenger()->addStatus("Content Reassigned");
81-
8289}
8390
8491/**
85- * * Implements hook_maestro_batch_handlers().
86- * *
87- * * Array of function names and help text that will be displayed
88- * * in the edit task form under the handler field.
89- * * /
92+ * Implements hook_maestro_batch_handlers().
93+ *
94+ * Array of function names and help text that will be displayed
95+ * in the edit task form under the handler field.
96+ */
9097function os2forms_forloeb_maestro_batch_handlers() {
9198 return [
9299 'end_notification_batch_function' => t('Batch function to send out flow completion notification to initiator.'),
93100 ];
94101}
95102
96103/**
97- * * @param int $processID
98- * * The Maestro process ID.
99- * * @param int $queueID
100- * * The Maestro queue ID.
101- * */
104+ * Finishing callback for batch handler.
105+ *
106+ * @param int $processID
107+ * The Maestro process ID.
108+ * @param int $queueID
109+ * The Maestro queue ID.
110+ */
102111function end_notification_batch_function($processID, $queueID) {
103112
104113 /*
@@ -116,7 +125,7 @@ function end_notification_batch_function($processID, $queueID) {
116125
117126 if ($sid) {
118127 $webform_submission = WebformSubmission::load($sid);
119- $webform = $webform_submission->getWebform();
128+ $webform = $webform_submission->getWebform();
120129 $handlers = $webform->getHandlers();
121130
122131 foreach ($handlers as $handler) {
@@ -131,27 +140,29 @@ function end_notification_batch_function($processID, $queueID) {
131140}
132141
133142/**
134- * Implements hook_ENTITY_TYPE_create()
143+ * Implements hook_ENTITY_TYPE_create().
144+ *
135145 * Sets a global purge setting for all webform submissions to 30 days.
136146 */
137147function os2forms_forloeb_webform_create(WebformInterface $webform) {
138- // Set purge of all users submissions.
139- $webform->setSetting('purge', 'all');
140- // Set purge of submissions more than 30 days old.
141- if (empty($webform->getSetting('purge_days'))) {
142- $webform->setSetting('purge_days', '30');
143- }
148+ // Set purge of all users submissions.
149+ $webform->setSetting('purge', 'all');
150+ // Set purge of submissions more than 30 days old.
151+ if (empty($webform->getSetting('purge_days'))) {
152+ $webform->setSetting('purge_days', '30');
153+ }
144154}
145155
146156/**
147- * Implements hook_ENTITY_TYPE_presave()
157+ * Implements hook_ENTITY_TYPE_presave().
158+ *
148159 * Update webform specific submissions purge settings.
149160 */
150161function os2forms_forloeb_webform_presave(WebformInterface $webform) {
151- // Add a purge time frame if not set.
152- if (empty($webform->getSetting('purge_days'))) {
153- $webform->setSetting('purge_days', 30);
154- }
162+ // Add a purge time frame if not set.
163+ if (empty($webform->getSetting('purge_days'))) {
164+ $webform->setSetting('purge_days', 30);
165+ }
155166}
156167
157168/**
@@ -203,8 +214,7 @@ function os2forms_forloeb_spv_fetch_entity_username($uniqueWebformIdentifier, $w
203214}
204215
205216/**
206- * Returns array of custom task-types for OS2forms
207- *
217+ * Returns array of custom task-types for OS2forms.
208218 */
209219function os2forms_forloeb_get_custom_task_types() {
210220 return ['MaestroWebformMultiple', 'MaestroWebformInherit'];
@@ -216,28 +226,29 @@ function os2forms_forloeb_get_custom_task_types() {
216226 * This has been copied from
217227 * maestro/maestro_webform/maestro_webform.module with a minimal but
218228 * necessary change. See https://www.drupal.org/project/maestro/issues/3243510
219- * When that issue has been fixed, this hook implementation can be safely deleted.
220- *
229+ * When that issue has been fixed, this hook implementation
230+ * can be safely deleted.
221231 */
222232function os2forms_forloeb_form_alter(&$form, FormStateInterface $form_state, $form_id) {
223233 $queueID = intval(\Drupal::request()->query->get('queueid', 0));
224234 $isMaestro = intval(\Drupal::request()->query->get('maestro', 0));
225235 // Both these keys need to exist.
226236 if ($isMaestro && $queueID) {
227237 $templateTask = MaestroEngine::getTemplateTaskByQueueID($queueID);
228- // Get array of custom task-types
238+ // Get array of custom task-types.
229239 $os2forms_forloeb_custom_task_types = os2forms_forloeb_get_custom_task_types();
230- // We only care about custom Task-types defined in os2forms_forloeb_get_custom_task_types()
240+ // We only care about custom Task-types
241+ // defined in os2forms_forloeb_get_custom_task_types()
231242 if ($templateTask && in_array($templateTask['tasktype'], $os2forms_forloeb_custom_task_types)) {
232243 $storage = $form_state->getStorage();
233244 if ($storage && array_key_exists('form_display', $storage)) {
234- $webformTypes = \Drupal::entityTypeManager()->getStorage('node_type')->loadMultiple();
235245 $thisForm = $storage['form_display']->get('bundle');
236246 $targetEntityType = $storage['form_display']->get('targetEntityType');
237247 if ($isMaestro == 1 &&
238248 $targetEntityType == 'webform_submission' &&
239249 $templateTask['data']['webform_machine_name'] == $thisForm) {
240- // We now know this is a webform submission. We are going to add in our own form fields here.
250+ // We now know this is a webform submission.
251+ // We are going to add in our own form fields here.
241252 $form['maestro'] = [
242253 '#tree' => TRUE,
243254 ];
@@ -268,8 +279,11 @@ function os2forms_forloeb_form_alter(&$form, FormStateInterface $form_state, $fo
268279 }
269280}
270281
282+ /**
283+ * Implements hook_preprocess_page().
284+ */
271285function os2forms_forloeb_preprocess_page(&$variables) {
272- $variables['#attached']['library'][] = 'os2forms_forloeb/os2forms_forloeb';
286+ $variables['#attached']['library'][] = 'os2forms_forloeb/os2forms_forloeb';
273287}
274288
275289/**
@@ -304,9 +318,10 @@ function os2forms_forloeb_tokens($type, array $tokens, array $data, array $optio
304318
305319/**
306320 * Implements hook_entity_access().
321+ *
307322 * Allows requests with tokens to view the entity.
308323 */
309- function os2forms_forloeb_entity_access(\Drupal\Core\Entity\ EntityInterface $entity, $operation, \Drupal\Core\Session\ AccountInterface $account) {
324+ function os2forms_forloeb_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
310325 if ($operation == 'update' && $entity instanceof WebformSubmission) {
311326 $token = \Drupal::request()->query->get('os2forms-forloeb-ws-token');
312327 if ($token && $token === $entity->getToken()) {
0 commit comments