Development

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

You must first sign up to be able to contribute.

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

Revision 11279, 2.2 kB (checked in by nicolas, 6 years ago)

[1.2] forthport of r11278: renamed valueAttributeValue to value_attribute_value (coding standard and api consistency)

  • 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    * @param  string $name        The element name
60    * @param  string $value       The this widget is checked if value is not null
61    * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
62    * @param  array  $errors      An array of errors for the field
63    *
64    * @return string An HTML tag string
65    *
66    * @see sfWidgetForm
67    */
68   public function render($name, $value = null, $attributes = array(), $errors = array())
69   {
70     if (!is_null($value) && $value !== false)
71     {
72       $attributes['checked'] = 'checked';
73     }
74
75     if (!isset($attributes['value']) && !is_null($this->getOption('value_attribute_value')))
76     {
77       $attributes['value'] = $this->getOption('value_attribute_value');
78     }
79
80     return parent::render($name, null, $attributes, $errors);
81   }
82 }
83
Note: See TracBrowser for help on using the browser.