Permalink
Browse files

Start making input generation use templates as well.

  • Loading branch information...
1 parent 35e01a1 commit 8543478cc223c79d61f2bea6ca3fe22b7fad5fcb @markstory markstory committed Mar 3, 2014
Showing with 13 additions and 7 deletions.
  1. +13 −7 src/View/Helper/FormHelper.php
View
20 src/View/Helper/FormHelper.php
@@ -146,6 +146,7 @@ class FormHelper extends Helper {
'formend' => '</form>',
'hiddenblock' => '<div style="display:none;">{{content}}</div>',
'input' => '<input type="{{type}}" name="{{name}}"{{attrs}}>',
+ 'inputsubmit' => '<input type="{{type}}"{{attrs}}>',
'label' => '<label{{attrs}}>{{text}}</label>',
'option' => '<option value="{{value}}"{{attrs}}>{{text}}</option>',
'optgroup' => '<optgroup label="{{label}}"{{attrs}}>{{content}}</optgroup>',
@@ -1489,6 +1490,9 @@ public function submit($caption = null, $options = array()) {
$isUrl = strpos($caption, '://') !== false;
$isImage = preg_match('/\.(jpg|jpe|jpeg|gif|png|ico)$/', $caption);
+ $type = $options['type'];
+ unset($options['type']);
+
if ($isUrl || $isImage) {
$unlockFields = array('x', 'y');
if (isset($options['name'])) {
@@ -1499,28 +1503,30 @@ public function submit($caption = null, $options = array()) {
foreach ($unlockFields as $ignore) {
$this->unlockField($ignore);
}
+ $type = 'image';
}
if ($isUrl) {
- unset($options['type']);
- $tag = $this->Html->useTag('submitimage', $caption, $options);
+ $options['src'] = $caption;
} elseif ($isImage) {
- unset($options['type']);
if ($caption{0} !== '/') {
$url = $this->webroot(Configure::read('App.imageBaseUrl') . $caption);
} else {
$url = $this->webroot(trim($caption, '/'));
}
$url = $this->assetTimestamp($url);
- $tag = $this->Html->useTag('submitimage', $url, $options);
+ $options['src'] = $url;
} else {
$options['value'] = $caption;
- $tag = $this->Html->useTag('submit', $options);
}
- $out = $tag;
+
+ $input = $this->formatTemplate('inputsubmit', [
+ 'type' => $type,
+ 'attrs' => $this->_templater->formatAttributes($options),
+ ]);
return $this->formatTemplate('submitContainer', [
- 'content' => $tag
+ 'content' => $input
]);
}

0 comments on commit 8543478

Please sign in to comment.