Skip to content
Snippets Groups Projects
Commit c10c7532 authored by Liam Morland's avatar Liam Morland Committed by Liam Morland
Browse files

Issue #3274842: Document hook_fillpdf_populate_pdf_context_alter()

parent 686fd3b4
No related branches found
No related tags found
No related merge requests found
<?php
/**
* @file
* Hooks related to FillPDF module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Alter the $context in HandlePdfController::populatePdf().
*
* @param array $context
* The context array with keys 'fid', 'force_download', 'flatten', 'sample',
* and 'entity_ids'.
*/
function hook_fillpdf_populate_pdf_context_alter(array &$context): void {
// If there are no webform_submission entities but there is at least one
// webform entity, add the most recent submission for each webform.
// Only do this for authenticated users and when webform_submission storage
// exists.
$current_uid = (int) \Drupal::currentUser()->id();
if ($current_uid && empty($context['entity_ids']['webform_submission']) && !empty($context['entity_ids']['webform']) && \Drupal::entityTypeManager()->hasDefinition('webform_submission')) {
$webform_submission_storage = \Drupal::entityTypeManager()->getStorage('webform_submission');
foreach ($context['entity_ids']['webform'] as $webform_id) {
// Load submission IDs from webform_submission storage.
$query = $webform_submission_storage->getQuery()->condition('webform_id', $webform_id);
$query->condition('uid', $uid);
$query->condition('in_draft', 0);
$query->sort('created', 'ASC');
$entity_id = $query->execute();
// If there is at least one, return the last as integer, otherwise NULL.
$entity_id = $entity_id ? (int) end($entity_id) : NULL;
if ($entity_id) {
$context['entity_ids']['webform_submission'][$entity_id] = $entity_id;
}
}
}
}
/**
* @} End of "addtogroup hooks".
*/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment