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
124c76c2
Commit
124c76c2
authored
5 years ago
by
qdoscc
Committed by
Kevin Kaland
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue #2189049 by wizonesolutions, qdoscc: Allow working with nodes in Rules
parent
0ad0c3a6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
fillpdf.module
+3
-1
3 additions, 1 deletion
fillpdf.module
fillpdf.rules.inc
+31
-0
31 additions, 0 deletions
fillpdf.rules.inc
tests/FillPdfMergeTestCase.test
+40
-0
40 additions, 0 deletions
tests/FillPdfMergeTestCase.test
with
74 additions
and
1 deletion
fillpdf.module
+
3
−
1
View file @
124c76c2
...
...
@@ -919,7 +919,9 @@ function fillpdf_load_entities($fillpdf_info, $nids, $webform_array, $uc_order_i
if
(
$entity_mode
)
{
// If no entity IDs are specified but we have a default NID, prime a plain
// entity ID here. The default entity type will be added just below.
if
(
empty
(
$entity_ids
)
&&
!
empty
(
$fillpdf_info
->
default_nid
))
{
// Note that we don't need a default entity if we already have a Node
// or Webform in context.
if
(
empty
(
$nids
)
&&
empty
(
$webform_array
)
&&
empty
(
$entity_ids
)
&&
!
empty
(
$fillpdf_info
->
default_nid
))
{
$entity_ids
=
array
(
$fillpdf_info
->
default_nid
);
}
...
...
This diff is collapsed.
Click to expand it.
fillpdf.rules.inc
+
31
−
0
View file @
124c76c2
...
...
@@ -80,6 +80,24 @@ function fillpdf_rules_action_info() {
),
),
),
'fillpdf_merge_node'
=>
$defaults
+
array
(
'label'
=>
t
(
'Fill a PDF with Node data'
),
'base'
=>
'fillpdf_rules_action_merge_node'
,
'description'
=>
t
(
'Populates the PDF with Node data and updates the
Rules variable with all information necessary to handle it.'
),
'parameter'
=>
array
(
'fillpdf'
=>
array
(
'type'
=>
'fillpdf'
,
'label'
=>
t
(
'FillPDF metadata'
),
),
'node_nid'
=>
array
(
'type'
=>
'integer'
,
'label'
=>
t
(
'Node ID'
),
'optional'
=>
TRUE
,
'description'
=>
t
(
'If you leave this blank, the <em>Default Node ID</em> from the FillPDF configuration will be used.'
),
),
),
),
'fillpdf_merge_webform'
=>
$defaults
+
array
(
'label'
=>
t
(
'Fill a PDF with webform data'
),
'base'
=>
'fillpdf_rules_action_merge_webform'
,
...
...
@@ -198,6 +216,19 @@ function fillpdf_rules_action_merge_webform($fillpdf, $webform_nid = '', $webfor
return
array
(
'fillpdf'
=>
$fillpdf
);
}
/**
* Populates a loaded FillPDF configuration's PDF with node data.
*/
function
fillpdf_rules_action_merge_node
(
$fillpdf
,
$node_nid
)
{
$skip_access_check
=
FALSE
;
$flatten
=
TRUE
;
$node_nid
=
array
(
$node_nid
);
// @todo: Parameterize $skip_access_check and $flatten in Rules.
$fillpdf
=
fillpdf_merge_pdf
(
$fillpdf
->
info
->
fid
,
$node_nid
,
NULL
,
NULL
,
FALSE
,
$skip_access_check
,
$flatten
,
FALSE
);
return
array
(
'fillpdf'
=>
$fillpdf
);
}
/**
* Save the PDF to a file and return the file path.
*/
...
...
This diff is collapsed.
Click to expand it.
tests/FillPdfMergeTestCase.test
+
40
−
0
View file @
124c76c2
...
...
@@ -104,6 +104,46 @@ class FillPdfMergeTestCase extends DrupalWebTestCase {
'PDF is populated with the title of the node.'
);
// *******************************
// *******************************
// Ensure entity defaults don't overpower legacy nids in links or
// fillpdf_merge_pdf() calls.
// *******************************
// *******************************
$default_nid_test_node
=
node_load
(
$this
->
createImageFieldEntity
(
$image
,
'field_test_image'
,
'node'
,
'article'
));
// Test with a node.
$this
->
uploadTestPdf
();
$fillpdf_form_default
=
fillpdf_load
(
$this
->
getLatestFillPdfForm
());
$this
->
drupalPost
(
"admin/structure/fillpdf/
{
$fillpdf_form_default
->
fid
}
"
,
array
(
'default_nid'
=>
$default_nid_test_node
->
nid
,
),
t
(
'Update'
));
// Get the field definitions for the form that was created and configure
// them.
$fid
=
$fillpdf_form_default
->
fid
;
$fields
=
fillpdf_get_fields
(
$fid
);
$this
->
mapFillPdfFieldsToEntityFields
(
'node'
,
$fields
,
$fillpdf_form_default
->
fid
);
// Hit the FillPDF URL, check the results from the test fill method.
$this
->
drupalGet
(
'fillpdf'
,
array
(
'query'
=>
array
(
'fid'
=>
$fillpdf_form_default
->
fid
,
'nid'
=>
$this
->
testNode
->
nid
,
),
));
// We don't actually care about downloading the fake PDF. We just want to
// check what happened in the backend.
$merge_result
=
variable_get
(
'fillpdf_test_last_merge_metadata'
);
$this
->
assertEqual
(
$merge_result
[
'fields'
][
'TextField'
],
$this
->
testNode
->
title
,
'Regression test: PDF is populated with the title of the correct node, not the default.'
);
// These tests cover the official (and some unofficial) ways of building
// FillPDF Links for entities. Official: entity_id, entity_ids, entity_type
// + entity_id. Unofficial: entity (synonym for entity_id), entities
...
...
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