Skip to content

Commit

Permalink
Fix for template selection for email pdf attachment. Form's PDF templ…
Browse files Browse the repository at this point in the history
…ate selection was getting overridden by menu details template selection.
  • Loading branch information
cheesegrits committed Aug 18, 2017
1 parent d5aceb8 commit dfe4a68
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
6 changes: 3 additions & 3 deletions components/com_fabrik/models/form.php
Expand Up @@ -352,7 +352,7 @@ class FabrikFEModelForm extends FabModelForm
*
* @var string
*/
private $tmpl = null;
public $tmpl = null;

/**
* Constructor
Expand Down Expand Up @@ -563,9 +563,9 @@ public function getTmpl()
$tmpl = $item->view_only_template == '' ? $default : $item->view_only_template;
}
}
}

$tmpl = FabrikWorker::getMenuOrRequestVar('fabriklayout', $tmpl, $this->isMambot);
$tmpl = FabrikWorker::getMenuOrRequestVar('fabriklayout', $tmpl, $this->isMambot);
}

// Finally see if the options are overridden by a querystring var
$baseTmpl = $tmpl;
Expand Down
39 changes: 23 additions & 16 deletions plugins/fabrik_form/email/email.php
Expand Up @@ -440,6 +440,11 @@ protected function pdfAttachment(&$thisAttachments)
$document->setType('pdf');
$input = $this->app->input;

/*
* * unset the template, to make sure view display picks up the PDF one
*/
$model->tmpl = null;

$orig['view'] = $input->get('view');
$orig['format'] = $input->get('format');

Expand All @@ -462,25 +467,10 @@ protected function pdfAttachment(&$thisAttachments)
// if DOMPDF isn't installed, this will throw an exception which we should catch
$domPdf = FabrikPDFHelper::iniDomPdf(true);

$model->getFormCss();

foreach ($document->_styleSheets as $url => $ss)
{
if (!strstr($url, COM_FABRIK_LIVESITE))
{
$url = COM_FABRIK_LIVESITE . $url;
}

$url = htmlspecialchars_decode($url);
$formCss[] = file_get_contents($url);
}


$size = strtoupper($params->get('pdf_size', 'A4'));
$orientation = $params->get('pdf_orientation', 'portrait');
$domPdf->set_paper($size, $orientation);


$controller = new FabrikControllerDetails;
/**
* $$$ hugh - stuff our model in there, with already formatted data, so it doesn't get rendered
Expand All @@ -496,12 +486,29 @@ protected function pdfAttachment(&$thisAttachments)
*/
$model->data = null;
$controller->_model->data = $model->getData();

$controller->_model->tmpl = null;
/*
* Allows us to bypass "view records" ACL settings for creating the details view
*/
$model->getListModel()->setLocalPdf();

/*
* get the CSS in a kinda hacky way
* (moved to after setting up the model and controller, so things like tmpl have been reset)
*/
$model->getFormCss();

foreach ($document->_styleSheets as $url => $ss)
{
if (!strstr($url, COM_FABRIK_LIVESITE))
{
$url = COM_FABRIK_LIVESITE . $url;
}

$url = htmlspecialchars_decode($url);
$formCss[] = file_get_contents($url);
}

// Store in output buffer
ob_start();
$controller->display();
Expand Down

0 comments on commit dfe4a68

Please sign in to comment.