Development

/branches/1.4/lib/widget/sfWidgetFormFilterInput.class.php

You must first sign up to be able to contribute.

root/branches/1.4/lib/widget/sfWidgetFormFilterInput.class.php

Revision 30762, 2.5 kB (checked in by fabien, 4 years ago)

[1.3, 1.4] fixed phpdoc (closes #8931)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * sfWidgetFormFilterInput represents an HTML input tag used for filtering text.
13  *
14  * @package    symfony
15  * @subpackage widget
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfWidgetFormFilterInput extends sfWidgetForm
20 {
21   /**
22    * Constructor.
23    *
24    * Available options:
25    *
26    *  * with_empty:  Whether to add the empty checkbox (true by default)
27    *  * empty_label: The label to use when using an empty checkbox
28    *  * template:    The template to use to render the widget
29    *                 Available placeholders: %input%, %empty_checkbox%, %empty_label%
30    *
31    * @param array $options     An array of options
32    * @param array $attributes  An array of default HTML attributes
33    *
34    * @see sfWidgetForm
35    */
36   protected function configure($options = array(), $attributes = array())
37   {
38     $this->addOption('with_empty', true);
39     $this->addOption('empty_label', 'is empty');
40     $this->addOption('template', '%input%<br />%empty_checkbox% %empty_label%');
41   }
42
43   /**
44    * Renders the widget.
45    *
46    * @param  string $name        The element name
47    * @param  string $value       The value displayed in this widget
48    * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
49    * @param  array  $errors      An array of errors for the field
50    *
51    * @return string An HTML tag string
52    *
53    * @see sfWidgetForm
54    */
55   public function render($name, $value = null, $attributes = array(), $errors = array())
56   {
57     $values = array_merge(array('text' => '', 'is_empty' => false), is_array($value) ? $value : array());
58
59     return strtr($this->getOption('template'), array(
60       '%input%'          => $this->renderTag('input', array_merge(array('type' => 'text', 'id' => $this->generateId($name), 'name' => $name.'[text]', 'value' => $values['text']), $attributes)),
61       '%empty_checkbox%' => $this->getOption('with_empty') ? $this->renderTag('input', array('type' => 'checkbox', 'name' => $name.'[is_empty]', 'checked' => $values['is_empty'] ? 'checked' : '')) : '',
62       '%empty_label%'    => $this->getOption('with_empty') ? $this->renderContentTag('label', $this->translate($this->getOption('empty_label')), array('for' => $this->generateId($name.'[is_empty]'))) : '',
63     ));
64   }
65 }
66
Note: See TracBrowser for help on using the browser.