Skip to content

Commit

Permalink
Start making input generation use templates as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 3, 2014
1 parent 35e01a1 commit 8543478
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/View/Helper/FormHelper.php
Expand Up @@ -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>',
Expand Down Expand Up @@ -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'])) {
Expand All @@ -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
]);
}

Expand Down

0 comments on commit 8543478

Please sign in to comment.