cvs: pear /HTML_QuickForm package.xml /HTML_QuickForm/QuickForm/Renderer ITStatic.php
| From: | Alexey Borzov | Date: | Mon, 28 Jun 2004 14:20:22 +0000 |
| Subject: | cvs: pear /HTML_QuickForm package.xml /HTML_QuickForm/QuickForm/Renderer ITStatic.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-21206@lists.php.net to get a copy of this message | ||
avb Mon Jun 28 10:20:22 2004 EDT
Modified files:
/pear/HTML_QuickForm package.xml
/pear/HTML_QuickForm/QuickForm/Renderer ITStatic.php
Log:
Implermentation of #553: ITStatic renderer can use template blocks
for required elements and errors
http://cvs.php.net/diff.php/pear/HTML_QuickForm/package.xml?r1=1.71&r2=1.72&ty=u
Index: pear/HTML_QuickForm/package.xml
diff -u pear/HTML_QuickForm/package.xml:1.71 pear/HTML_QuickForm/package.xml:1.72
--- pear/HTML_QuickForm/package.xml:1.71 Mon Jun 28 09:17:51 2004
+++ pear/HTML_QuickForm/package.xml Mon Jun 28 10:20:22 2004
@@ -70,7 +70,10 @@
on the element's name (see #1506)
- Default template of Default Renderer now allows XHTML-compliant output
of hidden elements (see #1124)
-- Added Esperanto translation and French accents for date element (Sebastien Montagne)
+- Added Esperanto translation and French accents for date element
+ (Sebastien Montagne)
+- Implemented #553: ITStatic renderer can use special blocks for required
+ elements and errors, if present in the template
* Bugfixes
- Fixed #1235 (setChecked() and setValue() did not work on advcheckbox)
http://cvs.php.net/diff.php/pear/HTML_QuickForm/QuickForm/Renderer/ITStatic.php?r1=1.6&r2=1.7&ty=u
Index: pear/HTML_QuickForm/QuickForm/Renderer/ITStatic.php
diff -u pear/HTML_QuickForm/QuickForm/Renderer/ITStatic.php:1.6
pear/HTML_QuickForm/QuickForm/Renderer/ITStatic.php:1.7
--- pear/HTML_QuickForm/QuickForm/Renderer/ITStatic.php:1.6 Mon Jun 28 09:17:24 2004
+++ pear/HTML_QuickForm/QuickForm/Renderer/ITStatic.php Mon Jun 28 10:20:22 2004
@@ -16,7 +16,7 @@
// | Author: Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
//
-// $Id: ITStatic.php,v 1.6 2004/06/28 13:17:24 mansion Exp $
+// $Id: ITStatic.php,v 1.7 2004/06/28 14:20:22 avb Exp $
require_once('HTML/QuickForm/Renderer.php');
@@ -257,7 +257,7 @@
*/
function renderHidden(&$element)
{
- if ($this->_tpl->placeholderExists($this->_formName .'_hidden')) {
+ if ($this->_tpl->placeholderExists($this->_formName . '_hidden')) {
$this->_hidden .= $element->toHtml();
} else {
$name = $element->getName();
@@ -297,12 +297,16 @@
// Uses error blocks to set the special groups layout error
// <!-- BEGIN form_group_error -->{form_group_error}<!-- END form_group_error
-->
if (!empty($error)) {
- if ($this->_tpl->placeholderExists($varName.'_error') &&
- (strpos($this->_error, '{html}') !== false ||
strpos($this->_error, '{label}') !== false)) {
- $error = str_replace('{error}', $error, $this->_error);
- $this->_tpl->setVariable($varName.'_error', $error);
- array_pop($this->_errors);
+ if ($this->_tpl->placeholderExists($varName.'_error')) {
+ if ($this->_tpl->blockExists($this->_formName .
'_error_block')) {
+ $this->_tpl->setVariable($this->_formName . '_error',
$error);
+ $error = $this->_getTplBlock($this->_formName .
'_error_block');
+ } elseif (strpos($this->_error, '{html}') !== false ||
strpos($this->_error, '{label}') !== false) {
+ $error = str_replace('{error}', $error, $this->_error);
+ }
}
+ $this->_tpl->setVariable($varName . '_error', $error);
+ array_pop($this->_errors);
}
}
if (is_array($label)) {
@@ -388,15 +392,30 @@
*/
function _renderRequired(&$label, &$html)
{
- if (!empty($label) && strpos($this->_required, '{label}') !== false) {
- if (is_array($label)) {
- $label[0] = str_replace('{label}', $label[0], $this->_required);
- } else {
- $label = str_replace('{label}', $label, $this->_required);
+ if ($this->_tpl->blockExists($tplBlock = $this->_formName .
'_required_block')) {
+ if (!empty($label) && $this->_tpl->placeholderExists($this->_formName
. '_label', $tplBlock)) {
+ $this->_tpl->setVariable($this->_formName . '_label',
is_array($label)? $label[0]: $label);
+ if (is_array($label)) {
+ $label[0] = $this->_getTplBlock($tplBlock);
+ } else {
+ $label = $this->_getTplBlock($tplBlock);
+ }
+ }
+ if (!empty($html) && $this->_tpl->placeholderExists($this->_formName .
'_html', $tplBlock)) {
+ $this->_tpl->setVariable($this->_formName . '_html', $html);
+ $html = $this->_getTplBlock($tplBlock);
+ }
+ } else {
+ if (!empty($label) && strpos($this->_required, '{label}') !==
false) {
+ if (is_array($label)) {
+ $label[0] = str_replace('{label}', $label[0], $this->_required);
+ } else {
+ $label = str_replace('{label}', $label, $this->_required);
+ }
+ }
+ if (!empty($html) && strpos($this->_required, '{html}') !== false)
{
+ $html = str_replace('{html}', $html, $this->_required);
}
- }
- if (!empty($html) && strpos($this->_required, '{html}') !== false) {
- $html = str_replace('{html}', $html, $this->_required);
}
} // end func _renderRequired
@@ -416,7 +435,22 @@
*/
function _renderError(&$label, &$html, $error)
{
- if (!empty($label) && strpos($this->_error, '{label}') !== false) {
+ if ($this->_tpl->blockExists($tplBlock = $this->_formName .
'_error_block')) {
+ $this->_tpl->setVariable($this->_formName . '_error', $error);
+ if (!empty($label) && $this->_tpl->placeholderExists($this->_formName
. '_label', $tplBlock)) {
+ $this->_tpl->setVariable($this->_formName . '_label',
is_array($label)? $label[0]: $label);
+ if (is_array($label)) {
+ $label[0] = $this->_getTplBlock($tplBlock);
+ } else {
+ $label = $this->_getTplBlock($tplBlock);
+ }
+ } elseif (!empty($html) &&
$this->_tpl->placeholderExists($this->_formName . '_html', $tplBlock)) {
+ $this->_tpl->setVariable($this->_formName . '_html', $html);
+ $html = $this->_getTplBlock($tplBlock);
+ }
+ // clean up after ourselves
+ $this->_tpl->setVariable($this->_formName . '_error', null);
+ } elseif (!empty($label) && strpos($this->_error, '{label}') !==
false) {
if (is_array($label)) {
$label[0] = str_replace(array('{label}', '{error}'),
array($label[0], $error), $this->_error);
} else {
@@ -428,5 +462,29 @@
$this->_errors[] = $error;
}
}// end func _renderError
+
+
+ /**
+ * Returns the block's contents
+ *
+ * The method is needed because ITX and Sigma implement clearing
+ * the block contents on get() a bit differently
+ *
+ * @param string Block name
+ * @return string Block contents
+ */
+ function _getTplBlock($block)
+ {
+ $this->_tpl->parse($block);
+ if (is_a($this->_tpl, 'html_template_sigma')) {
+ $ret = $this->_tpl->get($block, true);
+ } else {
+ $oldClear = $this->_tpl->clearCache;
+ $this->_tpl->clearCache = true;
+ $ret = $this->_tpl->get($block);
+ $this->_tpl->clearCache = $oldClear;
+ }
+ return $ret;
+ }
} // end class HTML_QuickForm_Renderer_ITStatic
?>