You are here

function fillpdf_pdf_link in FillPDF 7

Same name and namespace in other branches
  1. 6 fillpdf.module \fillpdf_pdf_link()
  2. 7.2 fillpdf.module \fillpdf_pdf_link()

Builds a link generating a printable PDF, merged with the passed-in data.

Note that every time the path is hit, the PDF form will be merged afresh with the passed-in data, generating a new populated PDF file.

You may provide multiple IDs of a particular type. In that case, tokens matching a later node, entity, webform etc. will override previous ones.

Parameters

int $fid: FillPDF form ID.

int|int[] $nids: A single node ID or an array thereof.

array|array[] $webform_arr: Array of webforms, of this strucure: array('nid'=>1, 'sid'=>1)

bool $sample: TRUE if you want to populate the form with its own field-names (to get a gist of PDF)

int|int[] $uc_order_ids: A single Ubercart order ID or an array thereof.

int|int[] $uc_order_product_ids: A single Ubercart order product ID or an array thereof.

string|string[] $entity_ids: A single entity ID given in the form <code>$entity_type:$id</code>, or an array thereof.

Return value

string The file generation URL.

5 calls to fillpdf_pdf_link()
FillPdfLinkBooleansTestCase::link in tests/FillPdfLinkBooleansTestCase.test
Input helper for testBooleans().
FillPdfNodeTestCase::testLegacyNodeLink in tests/FillPdfNodeTestCase.test
Test fillpdf_pdf_link() with a single node in legacy format.
FillPdfWebformTestCase::testLegacyWebformLink in tests/FillPdfWebformTestCase.test
Test fillpdf_pdf_link() with a single webform in legacy format.
fillpdf_context_to_link in ./fillpdf.module
Translates a FillPDF context array into a link.
fillpdf_form_edit in ./fillpdf.admin.inc
Edit existing PDF form.

File

./fillpdf.module, line 278

Code

function fillpdf_pdf_link($fid, $nids = NULL, array $webform_arr = NULL, $sample = FALSE, $uc_order_ids = NULL, $uc_order_product_ids = NULL, $entity_ids = NULL) {
  $query = array(
    'fid' => $fid,
  );
  if (!empty($nids)) {
    $nids = (array) $nids;
    $query += count($nids) > 1 ? array(
      'nids' => $nids,
    ) : array(
      'nid' => reset($nids),
    );
  }
  if (is_array($webform_arr) && count($webform_arr)) {
    $webform_arr = isset($webform_arr['nid'], $webform_arr['sid']) ? array(
      $webform_arr,
    ) : $webform_arr;
    $query += count($webform_arr) > 1 ? array(
      'webforms' => $webform_arr,
    ) : array(
      'webform' => reset($webform_arr),
    );
  }
  if (!empty($uc_order_ids)) {
    $uc_order_ids = (array) $uc_order_ids;
    $query += count($uc_order_ids) > 1 ? array(
      'uc_order_ids' => $uc_order_ids,
    ) : array(
      'uc_order_id' => reset($uc_order_ids),
    );
  }
  if (!empty($uc_order_product_ids)) {
    $uc_order_product_ids = (array) $uc_order_product_ids;
    $query += count($uc_order_product_ids) > 1 ? array(
      'uc_order_product_ids' => $uc_order_product_ids,
    ) : array(
      'uc_order_product_id' => reset($uc_order_product_ids),
    );
  }
  if (!empty($entity_ids)) {
    $entity_ids = (array) $entity_ids;
    $query += count($entity_ids) > 1 ? array(
      'entity_ids' => $entity_ids,
    ) : array(
      'entity_id' => reset($entity_ids),
    );
  }
  if ($sample) {
    $query['sample'] = 'true';
  }
  $options = array(
    'query' => $query,
    'absolute' => TRUE,
  );
  return url('fillpdf', $options);
}