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

Issue #1393012: Allow specifying default node.

This works with Webform nodes as the node as well.
parent fd9c0dbb
No related branches found
Tags 8.x-4.32
No related merge requests found
e?php
<?php
/**
* @file
......@@ -194,6 +194,14 @@ function fillpdf_form_edit($form, &$form_state, $fid) {
'#required' => TRUE,
);
$form['default_nid'] = array(
'#type' => 'textfield',
'#title' => t('Default Node ID'),
'#description' => t('When filling a PDF, use this node for the data source if no node is specified in the Fill PDF URL.'),
'#maxlength' => 10,
'#default_value' => $pdf_form->default_nid,
);
// @@TODO:
// They can upload a PDF any time, but fields will only be generated on add. Don't want to purge existing fields,
// however a user might have accidently uploaded an old template and discover much later (if it's substantially different, just
......@@ -321,6 +329,7 @@ function fillpdf_form_edit_submit($form, &$form_state) {
db_update('fillpdf_forms')
->fields(array(
'title' => $form_state['values']['title'],
'default_nid' => (int) $form_state['values']['default_nid'] > 0 ? (int) $form_state['values']['default_nid'] : NULL,
'destination_path' => $form_state['values']['destination_path'],
'replacements' => $form_state['values']['replacements'],
))
......@@ -695,3 +704,4 @@ function fillpdf_update_field(&$pdf_form, &$field, $old_key) {
->condition('pdf_key', $old_key)
->execute();
}
......@@ -24,6 +24,11 @@ function fillpdf_schema() {
'length' => 255,
'not null' => TRUE,
),
'default_nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
'url' => array(
'type' => 'varchar',
'length' => 255,
......@@ -134,3 +139,11 @@ function fillpdf_update_7003() {
variable_set('fillpdf_service', $variable_name_map[$default]);
}
}
/**
* Add field to store default NID.
*/
function fillpdf_update_7004() {
db_add_field('fillpdf_forms', 'default_nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE));
}
......@@ -227,7 +227,7 @@ function fillpdf_merge_pdf($fid, $nids = NULL, $webform_arr = NULL, $sample = NU
drupal_goto();
}
$fillpdf_info = db_query("SELECT title, url, destination_path, replacements FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => $fid))->fetch();
$fillpdf_info = db_query("SELECT title, default_nid, url, destination_path, replacements FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => $fid))->fetch();
$fillpdf_info->replacements = _fillpdf_replacements_to_array($fillpdf_info->replacements);
// Case 2: Only $fid -- just give them empty pdf
......@@ -240,6 +240,29 @@ function fillpdf_merge_pdf($fid, $nids = NULL, $webform_arr = NULL, $sample = NU
global $user;
$nodes = $webforms = array();
// If $webform_arr contains entries with an sid, but not an nid, set the nid to the default.
if (!empty($fillpdf_info->default_nid) && is_array($webform_arr)) {
foreach (array_keys($webform_arr) as $key) {
if (empty($webform_arr[$key]['nid'])) {
$webform_arr[$key]['nid'] = $fillpdf_info->default_nid;
}
}
}
// If no nid is given, use the default.
if (!empty($fillpdf_info->default_nid) && empty($nids) && empty($webform_arr)) {
$default_node = node_load($fillpdf_info->default_nid);
if ($default_node) {
if (empty($default_node->webform)) { // Default node is a non-webform node.
$nodes[] = $default_node;
}
else { // Default node is a webform.
$webform_arr = array(array('nid' => $fillpdf_info->default_nid, 'node' => $default_node));
}
}
}
// Nodes
if (is_array($nids)) {
foreach ($nids as $nid) {
......@@ -256,14 +279,16 @@ function fillpdf_merge_pdf($fid, $nids = NULL, $webform_arr = NULL, $sample = NU
}
foreach ($webform_arr as $webform) {
if (empty($webform['sid'])) { // User did not specify submission ID, meaning they want most recent.
$webform['sid'] = db_query('SELECT sid FROM {webform_submissions}
WHERE nid = :nid AND uid = :uid ORDER BY submitted DESC', array(':nid' => (int) $webform['nid'], ':uid' => (int) $user->uid))->fetchField();
if (!empty($webform['nid'])) {
if (empty($webform['sid'])) { // User did not specify submission ID, meaning they want most recent.
$webform['sid'] = db_query('SELECT sid FROM {webform_submissions}
WHERE nid = :nid AND uid = :uid ORDER BY submitted DESC', array(':nid' => $webform['nid'], ':uid' => $user->uid))->fetchField();
}
$webforms[] = array(
'webform' => empty($webform['node']) ? node_load($webform['nid']) : $webform['node'],
'submission' => webform_get_submission($webform['nid'], $webform['sid']),
);
}
$webforms[] = array(
'webform' => node_load($webform['nid']),
'submission' => webform_get_submission($webform['nid'], $webform['sid']),
);
}
}
......
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