Add support for sprintf to setHelp

clean - fix typo in php-end-tag cleaner
Input - support sprintf parameter
Select - put option-names through gettext
This commit is contained in:
Sjon Hortensius 2015-01-31 13:21:04 +01:00
parent d9f9836aa4
commit 276c29d403
3 changed files with 16 additions and 5 deletions

View File

@ -10,6 +10,6 @@ sed -i -e 's/> </></g' \
-e 's/<?php include("fbegin.inc"); ?>//g' \
-e 's/<?php include("fend.inc"); ?>/<?php include("foot.inc"); ?>/g' \
-e 's/<?php echo /<?=/g' \
-e 's/;\?\s*?>/?>/g' \
-e 's/;?\s*?>/?>/g' \
-e 's/<?\s*=\s*/<?=/g' \
$1
$1

View File

@ -6,6 +6,7 @@ class Form_Input extends Form_Element
protected $_name;
protected $_attributes;
protected $_help;
protected $_helpParams = array();
protected $_columnWidth;
protected $_columnClasses = array();
@ -44,9 +45,10 @@ class Form_Input extends Form_Element
return $this->_name;
}
public function setHelp($help)
public function setHelp($help, array $params = array())
{
$this->_help = $help;
$this->_helpParams = $params;
return $this;
}
@ -119,7 +121,16 @@ class Form_Input extends Form_Element
$this->_attributes['class'] = $this->getHtmlClass(false);
$input = $this->_getInput();
$help = isset($this->_help) ? '<span class="help-block">'. gettext($this->_help). '</span>' : '';
if (isset($this->_help))
{
$help = gettext($this->_help);
if (!empty($this->_helpParams))
$help = call_user_func_array('sprintf', array_merge([$help], $this->_helpParams));
$help = '<span class="help-block">'. $help .'</span>';
}
return <<<EOT
<div {$this->getColumnHtmlClass()}>

View File

@ -27,7 +27,7 @@ class Form_Select extends Form_Input
$options = '';
foreach ($this->_values as $value => $name)
$options .= '<option value="'. htmlspecialchars($value) .'">'. $name .'</option>';
$options .= '<option value="'. htmlspecialchars($value) .'">'. gettext($name) .'</option>';
return <<<EOT
<{$element}>