Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fillpdf
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
fillpdf
Commits
c10c7532
Commit
c10c7532
authored
2 years ago
by
Liam Morland
Committed by
Liam Morland
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue #3274842: Document hook_fillpdf_populate_pdf_context_alter()
parent
686fd3b4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fillpdf.api.php
+46
-0
46 additions, 0 deletions
fillpdf.api.php
with
46 additions
and
0 deletions
fillpdf.api.php
0 → 100644
+
46
−
0
View file @
c10c7532
<?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".
*/
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment