|
5 | 5 | * Install, update and uninstall functions for the os2forms_forloeb. |
6 | 6 | */ |
7 | 7 |
|
8 | | -use Drupal\Core\Access\AccessResult; |
9 | | -use Drupal\Core\Entity\EntityInterface; |
10 | 8 | use Drupal\Core\Form\FormStateInterface; |
11 | | -use Drupal\Core\Render\BubbleableMetadata; |
12 | | -use Drupal\Core\Session\AccountInterface; |
13 | | -use Drupal\Core\Url; |
14 | 9 | use Drupal\maestro\Engine\MaestroEngine; |
| 10 | +use Drupal\os2forms_forloeb\MaestroHelper; |
15 | 11 | use Drupal\os2forms_forloeb\Plugin\EngineTasks\MaestroWebformInheritTask; |
16 | 12 | use Drupal\user\Entity\User; |
17 | 13 | use Drupal\webform\Entity\WebformSubmission; |
18 | 14 | use Drupal\webform\WebformInterface; |
19 | | -use Drupal\webform\WebformSubmissionInterface; |
20 | 15 |
|
21 | 16 | /** |
22 | 17 | * Implements hook_maestro_interactive_handlers(). |
@@ -289,66 +284,93 @@ function os2forms_forloeb_preprocess_page(&$variables) { |
289 | 284 | } |
290 | 285 |
|
291 | 286 | /** |
292 | | - * Implements hook_token_info_alter(). |
| 287 | + * Implements hook_webform_submission_form_alter(). |
293 | 288 | */ |
294 | | -function os2forms_forloeb_token_info_alter(&$data) { |
295 | | - $data['tokens']['webform_submission']['os2forms_forloeb_execute_task'] = [ |
296 | | - 'name' => t('Execute task path for webform submission'), |
297 | | - 'description' => t("The token that can be user to get path for webform submission redirect URL."), |
298 | | - 'type' => 'webform_submission', |
299 | | - ]; |
| 289 | +function os2forms_forloeb_webform_submission_form_alter(array &$form, FormStateInterface $formState, string $formId) { |
| 290 | + MaestroWebformInheritTask::webformSubmissionFormAlter($form, $formState, $formId); |
| 291 | +} |
| 292 | + |
| 293 | +/** |
| 294 | + * Implements hook_maestro_zero_user_notification(). |
| 295 | + */ |
| 296 | +function os2forms_forloeb_maestro_zero_user_notification($templateMachineName, $taskMachineName, $queueID, $notificationType) { |
| 297 | + _os2forms_forloeb_helper()->maestroZeroUserNotification($templateMachineName, $taskMachineName, $queueID, $notificationType); |
300 | 298 | } |
301 | 299 |
|
302 | 300 | /** |
303 | | - * Implements hook_tokens(). |
| 301 | + * Implements hook_maestro_can_user_execute_task_alter(). |
304 | 302 | * |
305 | | - * Provides token value for webform_submission:os2forms_forloeb_execute_task. |
| 303 | + * For OS2Forms, you may have a consistent assignment to an "anonymous" user via |
| 304 | + * a role. Use the QueueID and userID to drill into the task and alter the |
| 305 | + * returnValue to TRUE if this is a user that should be looking at this task. |
| 306 | + * |
| 307 | + * You can make this as complex as you'd like it to be, checking things like |
| 308 | + * sessions, login tokens, email addresses etc. |
306 | 309 | */ |
307 | | -function os2forms_forloeb_tokens($type, array $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) { |
308 | | - $replacements = []; |
309 | | - |
310 | | - if ($type === 'webform_submission' && !empty($data['webform_submission']) && isset($tokens['os2forms_forloeb_execute_task'])) { |
311 | | - $replacements[$tokens['os2forms_forloeb_execute_task']] = Url::fromRoute( |
312 | | - 'os2forms_forloeb.forloeb_task_console_controller_execute', |
313 | | - ['os2forms-forloeb-ws-token' => $data['webform_submission']->getToken()], |
314 | | - ['absolute' => TRUE] |
315 | | - )->toString(TRUE)->getGeneratedUrl(); |
316 | | - } |
| 310 | +function os2forms_forloeb_maestro_can_user_execute_task_alter(&$returnValue, $queueID, $userID) { |
| 311 | + _os2forms_forloeb_helper()->maestroCanUserExecuteTaskAlter($returnValue, $queueID, $userID); |
| 312 | +} |
317 | 313 |
|
318 | | - return $replacements; |
| 314 | +/** |
| 315 | + * Implements hook_mail(). |
| 316 | + */ |
| 317 | +function os2forms_forloeb_mail($key, &$message, $params) { |
| 318 | + _os2forms_forloeb_helper()->mail($key, $message, $params); |
319 | 319 | } |
320 | 320 |
|
321 | 321 | /** |
322 | | - * Implements hook_entity_access(). |
323 | | - * |
324 | | - * Allows requests with tokens to view the entity. |
| 322 | + * Implements hook_mail_alter(). |
325 | 323 | */ |
326 | | -function os2forms_forloeb_entity_access(EntityInterface $entity, $operation, AccountInterface $account) { |
327 | | - if ($operation == 'update' && $entity instanceof WebformSubmission) { |
328 | | - $token = \Drupal::request()->query->get('os2forms-forloeb-ws-token'); |
329 | | - if ($token && $token === $entity->getToken()) { |
330 | | - return AccessResult::allowed(); |
331 | | - } |
332 | | - } |
333 | | - return AccessResult::neutral(); |
| 324 | +function os2forms_forloeb_mail_alter(&$message) { |
| 325 | + _os2forms_forloeb_helper()->mailAlter($message); |
334 | 326 | } |
335 | 327 |
|
336 | 328 | /** |
337 | | - * Implements hook_maestro_post_fetch_assigned_queue_tasks(). |
| 329 | + * Implements hook_theme(). |
338 | 330 | */ |
339 | | -function os2forms_forloeb_maestro_post_fetch_assigned_queue_tasks($userID, &$queueIDs) { |
340 | | - $token = \Drupal::request()->query->get('os2forms-forloeb-ws-token', ''); |
341 | | - if ($token) { |
342 | | - $forloebTaskConsole = Drupal::service('os2forms_forloeb.task_console'); |
343 | | - $queueRecord = $forloebTaskConsole->getQueueIdByWebformSubmissionToken($token); |
344 | | - $queueIDs[] = $queueRecord->id(); |
345 | | - $queueIDs = array_unique($queueIDs); |
346 | | - } |
| 331 | +function os2forms_forloeb_theme(array &$variables) { |
| 332 | + $theme['os2forms_forloeb_notification_preview'] = [ |
| 333 | + 'variables' => [ |
| 334 | + 'webform' => NULL, |
| 335 | + 'handler' => NULL, |
| 336 | + 'notification_type' => NULL, |
| 337 | + 'subject' => NULL, |
| 338 | + 'recipient' => NULL, |
| 339 | + 'content_type' => NULL, |
| 340 | + 'submission' => NULL, |
| 341 | + 'return_url' => NULL, |
| 342 | + 'render_url' => NULL, |
| 343 | + 'preview_urls' => [ |
| 344 | + 'prev' => NULL, |
| 345 | + 'self' => NULL, |
| 346 | + 'next' => NULL, |
| 347 | + ], |
| 348 | + ], |
| 349 | + ]; |
| 350 | + |
| 351 | + $theme['os2forms_forloeb_notification_message_email_html'] = [ |
| 352 | + 'variables' => [ |
| 353 | + 'message' => [ |
| 354 | + 'content' => [ |
| 355 | + 'value' => NULL, |
| 356 | + 'format' => NULL, |
| 357 | + ], |
| 358 | + ], |
| 359 | + 'task_url' => NULL, |
| 360 | + 'action_label' => NULL, |
| 361 | + 'webform_submission' => NULL, |
| 362 | + 'handler' => NULL, |
| 363 | + ], |
| 364 | + ]; |
| 365 | + |
| 366 | + $theme['os2forms_forloeb_notification_message_pdf_html'] = $theme['os2forms_forloeb_notification_message_email_html']; |
| 367 | + |
| 368 | + return $theme; |
347 | 369 | } |
348 | 370 |
|
349 | 371 | /** |
350 | | - * Implements hook_ENTITY_TYPE_prepare_form(). |
| 372 | + * Get MaestroHelper. |
351 | 373 | */ |
352 | | -function os2forms_forloeb_webform_submission_prepare_form(WebformSubmissionInterface $webform_submission, string $operation, FormStateInterface $form_state) { |
353 | | - MaestroWebformInheritTask::webformSubmissionPrepareForm($webform_submission, $operation, $form_state); |
| 374 | +function _os2forms_forloeb_helper(): MaestroHelper { |
| 375 | + return Drupal::service(MaestroHelper::class); |
354 | 376 | } |
0 commit comments