ZF-8730: Zend_View_Helper_HtmlElement doesn't handle boolean dijitParams correctly

Description

Currently, Zend_View_Helper_HtmlElement does not convert boolean Dijit parameters to strings, resulting in code that looks like the following:


    $callLength = new ZFExt_Dojo_HorizontalRangeSlider(
            'messageFilterCallLength',
            array(
                'label'                     => 'HorizontalSlider',
                'value'                     => "0,100",
                'minimum'                   => 0,
                'maximum'                   => 100,
                'discreteValues'            => 6,
                'intermediateChanges'       => true,
                'showButtons'               => false,
                'bottomDecorationDijit'     => 'HorizontalRule',
                'bottomDecorationContainer' => 'bottomContainer',
                'bottomDecorationLabels'    => array(
                        $this->_tr->_("0 SEC"),
                        '',
                        '',
                        '',
                        '',
                        $this->_tr->_("5 MINS"),
                ),
                'bottomDecorationParams' => array(
                    'container' => array(
                        'style' => 'height:5px;',
                        'count' => 6,
                    ),
                    'list' => array(
                        'style' => 'height:5px;',
                    ),
                ),
                'style' => 'width: 200px;',
            )
        );

Output:


0 SEC 5 MINS

The 'intermediateChanges="1" showButtons=""' is incorrect.

The function _htmlAttribs should be changed to the following:


    /**
     * Converts an associative array to a string of tag attributes. Fixes boolean error.
     *
     * @access public
     *
     * @param array $attribs From this array, each key-value pair is
     * converted to an attribute name and value.
     *
     * @return string The XHTML for the attributes.
     */
    protected function _htmlAttribs($attribs)
    {
        $xhtml = '';
        foreach ((array) $attribs as $key => $val) {
            $key = $this->view->escape($key);
            
            if(is_bool($val)) {
                $val = ($val) ? 'true':'false';
            }

            if (('on' == substr($key, 0, 2)) || ('constraints' == $key)) {
                // Don't escape event attributes; _do_ substitute double quotes with singles
                if (!is_scalar($val)) {
                    // non-scalar data should be cast to JSON first
                    require_once 'Zend/Json.php';
                    $val = Zend_Json::encode($val);
                }
                $val = preg_replace('/"([^"]*)":/', '$1:', $val);
            } else {
                if (is_array($val)) {
                    $val = implode(' ', $val);
                }
                $val = $this->view->escape($val);
            }

            if ('id' == $key) {
                $val = $this->_normalizeId($val);
            }

            if (strpos($val, '"') !== false) {
                $xhtml .= " $key='$val'";
            } else {
                $xhtml .= " $key=\"$val\"";
            }
            
        }
        return $xhtml;
    }

Output:


0 SEC 5 MINS

Comments

I set component and add code tag to the description.

Thanks, I missed the options to do that.