Skip to content

Commit

Permalink
[TASK] Extract html markup to a class property to be easily overwritt…
Browse files Browse the repository at this point in the history
…en by another PHP Class
  • Loading branch information
jmverges committed Jun 28, 2016
1 parent 71d1327 commit b094b51
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
13 changes: 11 additions & 2 deletions Classes/Ajax/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
class Validate
{

/**
* @var array
*/
protected $templates = array(
'spanSuccess' => '<span class="success">%s</span>',
'spanError' => '<span class="error">%s</span>',
);


/**
* Main method of the class.
*
Expand Down Expand Up @@ -60,7 +69,7 @@ public function main()
$view = $this->initView($content);
$content = $view->render($gp, $errors);
}
$content = '<span class="success">' . $content . '</span>';
$content = sprintf($this->templates['spanSuccess'], $content);
} else {
$content = \Typoheads\Formhandler\Utility\GeneralUtility::getSingle($this->settings['ajax.']['config.'], 'notOk');
if (strlen($content) === 0) {
Expand All @@ -72,7 +81,7 @@ public function main()
];
$content = $view->render($gp, $errors);
}
$content = '<span class="error">' . $content . '</span>';
$content = sprintf($this->templates['spanError'], $content);
}
print $content;
}
Expand Down
20 changes: 13 additions & 7 deletions Classes/AjaxHandler/JQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
*/
class JQuery extends \Typoheads\Formhandler\AjaxHandler\AbstractAjaxHandler
{
/**
* @var array
*/
protected $templates = array(
'spanLoading'=>'<span class="loading" id="loading_%s" style="display:none">%s</span>',
'spanResult'=>'<span id="result_%s" class="formhandler-ajax-validation-result">%s</span>',
'aRemoveLink'=>'<a class="formhandler_removelink" href="%s">%s</a>',
);

/**
* Position of JS generated by AjaxHandler_JQuery (head|footer)
*
Expand Down Expand Up @@ -156,11 +165,8 @@ public function fillAjaxMarkers(&$markers)
if (is_array($validatorSettings['config.']['fieldConf.']) && intval($this->utilityFuncs->getSingle($validatorSettings['config.'], 'disable')) !== 1) {
foreach ($validatorSettings['config.']['fieldConf.'] as $fieldname => $fieldSettings) {
$replacedFieldname = str_replace('.', '', $fieldname);

$markers['###validate_' . $replacedFieldname . '###'] = '
<span class="loading" id="loading_' . $replacedFieldname . '" style="display:none">' . $loadingImg . '</span>
<span id="result_' . $replacedFieldname . '" class="formhandler-ajax-validation-result">' . str_replace('###fieldname###', $replacedFieldname, $initial) . '</span>
';
$markers['###validate_' . $replacedFieldname . '###'] = sprintf($this->templates['spanLoading'], $replacedFieldname, $loadingImg);
$markers['###validate_' . $replacedFieldname . '###'] .= sprintf($this->templates['spanResult'], $replacedFieldname, str_replace('###fieldname###', $replacedFieldname, $initial));
}
}
}
Expand All @@ -183,7 +189,7 @@ public function getFileRemovalLink($text, $field, $uploadedFileName)
'uploadedFileName' => $uploadedFileName
];
$url = $this->utilityFuncs->getAjaxUrl($params);
return '<a class="formhandler_removelink" href="' . $url . '">' . $text . '</a>';
return sprintf($this->templates['aRemoveLink'], $url, $text );
}

protected function addJS($js, $key = '', $doAppend = true)
Expand All @@ -205,4 +211,4 @@ protected function addJS($js, $key = '', $doAppend = true)
}
}

}
}

0 comments on commit b094b51

Please sign in to comment.