Permalink
Browse files

Implementing filtering in `\template\helper\Form::error()`.

  • Loading branch information...
1 parent cf9b2e6 commit c0d4ff82b1b3bb662ed0e78ed9599437306ca068 @nateabele nateabele committed Aug 12, 2011
Showing with 26 additions and 14 deletions.
  1. +26 −14 template/helper/Form.php
View
@@ -665,29 +665,41 @@ public function error($name, $key = null, array $options = array()) {
$defaults = array('class' => 'error');
list(, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
$options += $defaults;
- $result = '';
- if (isset($options['value'])) {
- unset($options['value']);
- }
+ $_binding =& $this->_binding;
+ $params = compact('name', 'key', 'options', 'template');
- if (!$this->_binding || !$content = $this->_binding->errors($name)) {
- return null;
- }
+ return $this->_filter(__METHOD__, $params, function($self, $params) use (&$_binding) {
+ $options = $params['options'];
+ $template = $params['template'];
+
+ if (isset($options['value'])) {
+ unset($options['value']);
+ }
+ if (!$_binding || !$content = $_binding->errors($params['name'])) {
+ return null;
+ }
+ $result = '';
- if (is_array($content)) {
+ if (!is_array($content)) {
+ $args = array(__METHOD__, $template, compact('content', 'options'));
+ return $self->invokeMethod('_render', $args);
+ }
$errors = $content;
- if ($key !== null) {
- $content = !isset($errors[$key]) || $key === true ? reset($errors) : $errors[$key];
- } else {
+ if ($params['key'] === null) {
foreach ($errors as $content) {
- $result .= $this->_render(__METHOD__, $template, compact('content', 'options'));
+ $args = array(__METHOD__, $template, compact('content', 'options'));
+ $result .= $self->invokeMethod('_render', $args);
}
return $result;
}
- }
- return $this->_render(__METHOD__, $template, compact('content', 'options'));
+
+ $key = $params['key'];
+ $content = !isset($errors[$key]) || $key === true ? reset($errors) : $errors[$key];
+ $args = array(__METHOD__, $template, compact('content', 'options'));
+ return $self->invokeMethod('_render', $args);
+ });
}
/**

0 comments on commit c0d4ff8

Please sign in to comment.