Skip to content
Snippets Groups Projects
Commit 124c76c2 authored by qdoscc's avatar qdoscc Committed by Kevin Kaland
Browse files

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
...@@ -919,7 +919,9 @@ function fillpdf_load_entities($fillpdf_info, $nids, $webform_array, $uc_order_i ...@@ -919,7 +919,9 @@ function fillpdf_load_entities($fillpdf_info, $nids, $webform_array, $uc_order_i
if ($entity_mode) { if ($entity_mode) {
// If no entity IDs are specified but we have a default NID, prime a plain // 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. // 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); $entity_ids = array($fillpdf_info->default_nid);
} }
......
...@@ -80,6 +80,24 @@ function fillpdf_rules_action_info() { ...@@ -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( 'fillpdf_merge_webform' => $defaults + array(
'label' => t('Fill a PDF with webform data'), 'label' => t('Fill a PDF with webform data'),
'base' => 'fillpdf_rules_action_merge_webform', 'base' => 'fillpdf_rules_action_merge_webform',
...@@ -198,6 +216,19 @@ function fillpdf_rules_action_merge_webform($fillpdf, $webform_nid = '', $webfor ...@@ -198,6 +216,19 @@ function fillpdf_rules_action_merge_webform($fillpdf, $webform_nid = '', $webfor
return array('fillpdf' => $fillpdf); 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. * Save the PDF to a file and return the file path.
*/ */
......
...@@ -104,6 +104,46 @@ class FillPdfMergeTestCase extends DrupalWebTestCase { ...@@ -104,6 +104,46 @@ class FillPdfMergeTestCase extends DrupalWebTestCase {
'PDF is populated with the title of the node.' '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 // These tests cover the official (and some unofficial) ways of building
// FillPDF Links for entities. Official: entity_id, entity_ids, entity_type // FillPDF Links for entities. Official: entity_id, entity_ids, entity_type
// + entity_id. Unofficial: entity (synonym for entity_id), entities // + entity_id. Unofficial: entity (synonym for entity_id), entities
......
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