Skip to content

Commit

Permalink
Fix templates path deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hubert Prein committed Apr 4, 2016
1 parent 017b520 commit ef18968
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion AmFormsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getName()
*/
public function getVersion()
{
return '1.3.5';
return '1.3.6';
}

/**
Expand Down
5 changes: 3 additions & 2 deletions services/AmFormsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,14 @@ public function renderDisplayTemplate($defaultTemplate, $overrideTemplate, $vari
$templateInfo = $this->getDisplayTemplateInfo($defaultTemplate, $overrideTemplate);

// Override Craft template path
craft()->path->setTemplatesPath($templateInfo['path']);
$oldPath = method_exists(craft()->templates, 'getTemplatesPath') ? craft()->templates->getTemplatesPath() : craft()->path->getTemplatesPath();
method_exists(craft()->templates, 'setTemplatesPath') ? craft()->templates->setTemplatesPath($templateInfo['path']) : craft()->path->setTemplatesPath($templateInfo['path']);

// Get template HTML
$html = craft()->templates->render($templateInfo['template'], $variables);

// Reset templates path
craft()->path->setTemplatesPath(craft()->path->getSiteTemplatesPath());
method_exists(craft()->templates, 'setTemplatesPath') ? craft()->templates->setTemplatesPath($oldPath) : craft()->path->setTemplatesPath($oldPath);

// Return rendered template!
return $html;
Expand Down
5 changes: 3 additions & 2 deletions services/AmForms_AntispamService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ public function render()
$rendered = array();

// Plugin's default template path
$oldPath = method_exists(craft()->templates, 'getTemplatesPath') ? craft()->templates->getTemplatesPath() : craft()->path->getTemplatesPath();
$templatePath = craft()->path->getPluginsPath() . 'amforms/templates/_display/templates/_antispam/';
craft()->path->setTemplatesPath($templatePath);
method_exists(craft()->templates, 'setTemplatesPath') ? craft()->templates->setTemplatesPath($templatePath) : craft()->path->setTemplatesPath($templatePath);

// Honeypot enabled?
if ($antispamSettings['honeypotEnabled']->value) {
Expand Down Expand Up @@ -73,7 +74,7 @@ public function render()
}

// Reset templates path
craft()->path->setTemplatesPath(craft()->path->getSiteTemplatesPath());
method_exists(craft()->templates, 'setTemplatesPath') ? craft()->templates->setTemplatesPath($oldPath) : craft()->path->setTemplatesPath($oldPath);

// Parse antispam protection
if (count($rendered)) {
Expand Down
16 changes: 8 additions & 8 deletions services/AmForms_FormsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function displayField(AmForms_FormModel $form, $handle)
$templatePath = $fieldTemplateInfo['path'];

// Get the current templates path so we can restore it at the end of this function
$siteTemplatesPath = craft()->path->getTemplatesPath();
$siteTemplatesPath = method_exists(craft()->templates, 'getTemplatesPath') ? craft()->templates->getTemplatesPath() : craft()->path->getTemplatesPath();
$pluginTemplateInfo = craft()->amForms->getDisplayTemplateInfo('field', false);
$pluginTemplatePath = $pluginTemplateInfo['path'];

Expand All @@ -239,15 +239,15 @@ public function displayField(AmForms_FormModel $form, $handle)
}

// Reset templates path for input and get field input
craft()->path->setTemplatesPath($pluginTemplatePath);
method_exists(craft()->templates, 'setTemplatesPath') ? craft()->templates->setTemplatesPath($pluginTemplatePath) : craft()->path->setTemplatesPath($pluginTemplatePath);
$fieldInfo = craft()->fields->populateFieldType($field, $submission);

craft()->templates->getTwig()->addGlobal('required', $layoutField->required);
$input = $fieldInfo->getInputHtml($field->handle, $submission->getFieldValue($field->handle));
craft()->templates->getTwig()->addGlobal('required', null);

// Get field HTML
craft()->path->setTemplatesPath($fieldTemplateInfo['path']);
method_exists(craft()->templates, 'setTemplatesPath') ? craft()->templates->setTemplatesPath($fieldTemplateInfo['path']) : craft()->path->setTemplatesPath($fieldTemplateInfo['path']);
$fieldHtml = craft()->templates->render($fieldTemplateInfo['template'], array(
'form' => $form,
'field' => $field,
Expand All @@ -263,7 +263,7 @@ public function displayField(AmForms_FormModel $form, $handle)
}

// Restore the templates path variable to it's original value
craft()->path->setTemplatesPath($siteTemplatesPath);
method_exists(craft()->templates, 'setTemplatesPath') ? craft()->templates->setTemplatesPath($siteTemplatesPath) : craft()->path->setTemplatesPath($siteTemplatesPath);

// Return field!
if (isset($this->_fields[$form->id][$handle])) {
Expand Down Expand Up @@ -293,7 +293,7 @@ public function displayForm(AmForms_FormModel $form)
$templatePath = $fieldTemplateInfo['path'];

// Get the current templates path so we can restore it at the end of this function
$siteTemplatesPath = craft()->path->getTemplatesPath();
$siteTemplatesPath = method_exists(craft()->templates, 'getTemplatesPath') ? craft()->templates->getTemplatesPath() : craft()->path->getTemplatesPath();
$pluginTemplateInfo = craft()->amForms->getDisplayTemplateInfo('field', false);
$pluginTemplatePath = $pluginTemplateInfo['path'];

Expand All @@ -315,15 +315,15 @@ public function displayForm(AmForms_FormModel $form)
}

// Reset templates path for input and get field input
craft()->path->setTemplatesPath($pluginTemplatePath);
method_exists(craft()->templates, 'setTemplatesPath') ? craft()->templates->setTemplatesPath($pluginTemplatePath) : craft()->path->setTemplatesPath($pluginTemplatePath);
$fieldInfo = craft()->fields->populateFieldType($field, $submission);

craft()->templates->getTwig()->addGlobal('required', $layoutField->required);
$input = $fieldInfo->getInputHtml($field->handle, $submission->getFieldValue($field->handle));
craft()->templates->getTwig()->addGlobal('required', null);

// Get field HTML
craft()->path->setTemplatesPath($fieldTemplateInfo['path']);
method_exists(craft()->templates, 'setTemplatesPath') ? craft()->templates->setTemplatesPath($fieldTemplateInfo['path']) : craft()->path->setTemplatesPath($fieldTemplateInfo['path']);
$tabs[$tab->id]['fields'][] = craft()->templates->render($fieldTemplateInfo['template'], array(
'form' => $form,
'field' => $field,
Expand All @@ -335,7 +335,7 @@ public function displayForm(AmForms_FormModel $form)
}

// Restore the templates path variable to it's original value
craft()->path->setTemplatesPath($siteTemplatesPath);
method_exists(craft()->templates, 'setTemplatesPath') ? craft()->templates->setTemplatesPath($siteTemplatesPath) : craft()->path->setTemplatesPath($siteTemplatesPath);

// Build tab HTML
$variables = array(
Expand Down
5 changes: 3 additions & 2 deletions services/AmForms_RecaptchaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ public function render()
$templatePath = craft()->path->getPluginsPath() . 'amforms/templates/_display/templates/';

// Build reCAPTCHA HTML
craft()->path->setTemplatesPath($templatePath);
$oldPath = method_exists(craft()->templates, 'getTemplatesPath') ? craft()->templates->getTemplatesPath() : craft()->path->getTemplatesPath();
method_exists(craft()->templates, 'setTemplatesPath') ? craft()->templates->setTemplatesPath($templatePath) : craft()->path->setTemplatesPath($templatePath);
$html = craft()->templates->render('recaptcha', array(
'siteKey' => $recaptchaSettings['siteKey']->value
));

// Reset templates path
craft()->path->setTemplatesPath(craft()->path->getSiteTemplatesPath());
method_exists(craft()->templates, 'setTemplatesPath') ? craft()->templates->setTemplatesPath($oldPath) : craft()->path->setTemplatesPath($oldPath);

// Include Google's reCAPTCHA API
craft()->templates->includeJsFile('https://www.google.com/recaptcha/api.js');
Expand Down

0 comments on commit ef18968

Please sign in to comment.