Development

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

You must first sign up to be able to contribute.

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

Revision 30762, 2.3 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  * sfWidgetFormInputCheckbox represents an HTML checkbox tag.
13  *
14  * @package    symfony
15  * @subpackage widget
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfWidgetFormInputCheckbox extends sfWidgetFormInput
20 {
21   /**
22    * Constructor.
23    *
24    * Available options:
25    *
26    *  - value_attribute_value: The "value" attribute value to set for the checkbox
27    *
28    * @param array  $options     An array of options
29    * @param array  $attributes  An array of default HTML attributes
30    *
31    * @see sfWidgetFormInput
32    */
33   public function __construct($options = array(), $attributes = array())
34   {
35     $this->addOption('value_attribute_value');
36
37     parent::__construct($options, $attributes);
38   }
39
40   /**
41    * @param array $options     An array of options
42    * @param array $attributes  An array of default HTML attributes
43    *
44    * @see sfWidgetFormInput
45    */
46   protected function configure($options = array(), $attributes = array())
47   {
48     parent::configure($options, $attributes);
49
50     $this->setOption('type', 'checkbox');
51
52     if (isset($attributes['value']))
53     {
54       $this->setOption('value_attribute_value', $attributes['value']);
55     }
56   }
57
58   /**
59    * Renders the widget.
60    *
61    * @param  string $name        The element name
62    * @param  string $value       The this widget is checked if value is not null
63    * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
64    * @param  array  $errors      An array of errors for the field
65    *
66    * @return string An HTML tag string
67    *
68    * @see sfWidgetForm
69    */
70   public function render($name, $value = null, $attributes = array(), $errors = array())
71   {
72     if (null !== $value && $value !== false)
73     {
74       $attributes['checked'] = 'checked';
75     }
76
77     if (!isset($attributes['value']) && null !== $this->getOption('value_attribute_value'))
78     {
79       $attributes['value'] = $this->getOption('value_attribute_value');
80     }
81
82     return parent::render($name, null, $attributes, $errors);
83   }
84 }
85
Note: See TracBrowser for help on using the browser.