Skip to content

Commit

Permalink
Fix custom field template
Browse files Browse the repository at this point in the history
  • Loading branch information
Hubert Prein committed Dec 22, 2015
1 parent 1a7ebab commit 40aa9eb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions services/AmForms_FormsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ 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
$oldTemplatesPath = craft()->path->getTemplatesPath();
$siteTemplatesPath = craft()->path->getTemplatesPath();
$pluginTemplateInfo = craft()->amForms->getDisplayTemplateInfo('field', false);
$pluginTemplatePath = $pluginTemplateInfo['path'];

// Do we have the current form fields?
if (! isset($this->_fields[$form->id])) {
Expand All @@ -232,7 +234,7 @@ public function displayField(AmForms_FormModel $form, $handle)
$field = $layoutField->getField();

// Reset templates path for input and get field input
craft()->path->setTemplatesPath($templatePath);
craft()->path->setTemplatesPath($pluginTemplatePath);
$fieldInfo = craft()->fields->populateFieldType($field, $submission);
$input = $fieldInfo->getInputHtml($field->handle, $submission->getFieldValue($field->handle));
if ($layoutField->required) {
Expand All @@ -257,7 +259,7 @@ public function displayField(AmForms_FormModel $form, $handle)
}

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

// Return field!
if (isset($this->_fields[$form->id][$handle])) {
Expand Down Expand Up @@ -287,7 +289,9 @@ 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
$oldTemplatesPath = craft()->path->getTemplatesPath();
$siteTemplatesPath = craft()->path->getTemplatesPath();
$pluginTemplateInfo = craft()->amForms->getDisplayTemplateInfo('field', false);
$pluginTemplatePath = $pluginTemplateInfo['path'];

foreach ($form->getFieldLayout()->getTabs() as $tab) {
// Tab information
Expand All @@ -307,7 +311,7 @@ public function displayForm(AmForms_FormModel $form)
}

// Reset templates path for input and get field input
craft()->path->setTemplatesPath($templatePath);
craft()->path->setTemplatesPath($pluginTemplatePath);
$fieldInfo = craft()->fields->populateFieldType($field, $submission);
$input = $fieldInfo->getInputHtml($field->handle, $submission->getFieldValue($field->handle));
if ($layoutField->required) {
Expand All @@ -328,7 +332,7 @@ public function displayForm(AmForms_FormModel $form)
}

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

// Build tab HTML
$variables = array(
Expand Down

0 comments on commit 40aa9eb

Please sign in to comment.