web/lib/Zend/View/Helper/FormLabel.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_View
       
    17  * @subpackage Helper
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: FormLabel.php 22290 2010-05-25 14:27:12Z matthew $
       
    21  */
       
    22 
       
    23 /** Zend_View_Helper_FormElement **/
       
    24 require_once 'Zend/View/Helper/FormElement.php';
       
    25 
       
    26 /**
       
    27  * Form label helper
       
    28  *
       
    29  * @category   Zend
       
    30  * @package    Zend_View
       
    31  * @subpackage Helper
       
    32  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    33  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    34  */
       
    35 class Zend_View_Helper_FormLabel extends Zend_View_Helper_FormElement
       
    36 {
       
    37     /**
       
    38      * Generates a 'label' element.
       
    39      *
       
    40      * @param  string $name The form element name for which the label is being generated
       
    41      * @param  string $value The label text
       
    42      * @param  array $attribs Form element attributes (used to determine if disabled)
       
    43      * @return string The element XHTML.
       
    44      */
       
    45     public function formLabel($name, $value = null, array $attribs = null)
       
    46     {
       
    47         $info = $this->_getInfo($name, $value, $attribs);
       
    48         extract($info); // name, value, attribs, options, listsep, disable, escape
       
    49 
       
    50         // build the element
       
    51         if ($disable) {
       
    52             // disabled; display nothing
       
    53             return  '';
       
    54         }
       
    55 
       
    56         $value = ($escape) ? $this->view->escape($value) : $value;
       
    57         $for   = (empty($attribs['disableFor']) || !$attribs['disableFor'])
       
    58                ? ' for="' . $this->view->escape($id) . '"'
       
    59                : '';
       
    60         if (array_key_exists('disableFor', $attribs)) {
       
    61             unset($attribs['disableFor']);
       
    62         }
       
    63 
       
    64         // enabled; display label
       
    65         $xhtml = '<label'
       
    66                 . $for
       
    67                 . $this->_htmlAttribs($attribs)
       
    68                 . '>' . $value . '</label>';
       
    69 
       
    70         return $xhtml;
       
    71     }
       
    72 }