Skip to content

Commit

Permalink
Consistently use formatTemplate()
Browse files Browse the repository at this point in the history
`formatTemplate()` is a method that can be overwritten by plugins. It is also a method that can be called by the user to manually build customized form elements (e.g. adding extra elements to a `submitContainer`).

Right now FormHelper inconsistently uses `formatTemplate()` or `$this->templater()->format()`. It should in all cases use `formatTemplate()` however, as to provide the same experience to the user in both cases (internal or external use).
Furthermore, overwriting `formatTemplate()` is a powerful tool for plugins, only if it is also consistently called internally.
  • Loading branch information
ypnos-web committed Feb 17, 2016
1 parent 25665c2 commit fdf9b86
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/View/Helper/FormHelper.php
Expand Up @@ -428,7 +428,7 @@ public function create($model = null, array $options = [])
}

$actionAttr = $templater->formatAttributes(['action' => $action, 'escape' => false]);
return $templater->format('formStart', [
return $this->formatTemplate('formStart', [
'attrs' => $templater->formatAttributes($htmlAttributes) . $actionAttr
]) . $append;
}
Expand Down Expand Up @@ -529,10 +529,9 @@ public function end(array $secureAttributes = [])
$out .= $this->secure($this->fields, $secureAttributes);
$this->fields = [];
}
$templater = $this->templater();
$out .= $templater->format('formEnd', []);
$out .= $this->formatTemplate('formEnd', []);

$templater->pop();
$this->templater()->pop();
$this->requestType = null;
$this->_context = null;
$this->_idPrefix = $this->config('idPrefix');
Expand Down Expand Up @@ -1057,7 +1056,7 @@ protected function _groupTemplate($options)
if (!$this->templater()->get($groupTemplate)) {
$groupTemplate = 'formGroup';
}
return $this->templater()->format($groupTemplate, [
return $this->formatTemplate($groupTemplate, [
'input' => $options['input'],
'label' => $options['label'],
'error' => $options['error'],
Expand All @@ -1078,7 +1077,7 @@ protected function _inputContainerTemplate($options)
$inputContainerTemplate = 'inputContainer' . $options['errorSuffix'];
}

return $this->templater()->format($inputContainerTemplate, [
return $this->formatTemplate($inputContainerTemplate, [
'content' => $options['content'],
'error' => $options['error'],
'required' => $options['options']['required'] ? ' required' : '',
Expand Down Expand Up @@ -1668,7 +1667,7 @@ public function postLink($title, $url = null, array $options = [])
'escape' => false
]);

$out = $templater->format('formStart', [
$out = $this->formatTemplate('formStart', [
'attrs' => $templater->formatAttributes($formOptions) . $action
]);
$out .= $this->hidden('_method', ['value' => $requestMethod]);
Expand All @@ -1683,7 +1682,7 @@ public function postLink($title, $url = null, array $options = [])
unset($options['data']);
}
$out .= $this->secure($fields);
$out .= $templater->format('formEnd', []);
$out .= $this->formatTemplate('formEnd', []);

if ($options['block']) {
if ($options['block'] === true) {
Expand Down

0 comments on commit fdf9b86

Please sign in to comment.