Issues

ZF-7212: ulId to be added similar with ulClass

Issue Type: Improvement Created: 2009-07-07T02:03:19.000+0000 Last Updated: 2012-06-15T14:29:05.000+0000 Status: Resolved Fix version(s): - 1.12.0 (27/Aug/12)

Reporter: Cristian Bichis (avantis) Assignee: Frank Brückner (frosch) Tags: - Zend_Navigation

  • FixForZF1.12
  • state:patch-ready-for-review
  • zf-crteam-padraic
  • zf-crteam-priority
  • zf-crteam-review

Related issues: - ZF-10233

Attachments: - Navigation.patch

Description

I think we should add an ulId param, not just an ulClass.

In certain situations there is more likely to have the ul identified by ID.

Comments

Posted by Helder Correia (heldercorreia) on 2010-04-01T09:19:39.000+0000

I completely agree with you on this. I need it right now.

Posted by PHP4Dev (php4dev) on 2010-04-03T05:07:05.000+0000

I agree totaly. The class is declared in Zend/View/Helper/Navigation/Menu.php in line 425.

Posted by Maurice Bonemeijer (sugoi) on 2010-07-27T02:40:25.000+0000

I agree as well.

Some situations where an id would be desired: * in many cases it's more efficient to write css selectors based on id * certain js menu's out there rely on id

I would expect setting an id on a navigation container would be part of the most basic features.

Posted by Kai Uwe (kaiuwe) on 2011-01-28T09:51:45.000+0000

The patch should include the following points:

<pre class="highlight">
// start new ul tag
if ($ulClass && $depth ==  0) {
    $ulClass = ' class="' . $ulClass . '"';
} else {
    $ulClass = '';
}
$html .= $myIndent . '

' . self::EOL;


<pre class="highlight">
$attribs = array();

// start new ul tag
if (0 == $depth) {
    $attribs = array(
        'class' => $ulClass,
        'id'    => $ulId,
    );
}

$html .= $myIndent . '

_htmlAttribs($attribs)
                   . '>'
                   . self::EOL;

Zend_View_Helper_HtmlElement::_htmlAttribs() uses the method "_normalizeId"!

<pre class="highlight">
protected function _normalizeId($value)
{
    $prefix = get_class($this);
    $prefix = strtolower(trim(substr($prefix, strrpos($prefix, '_')), '_'));

    return $prefix . '-' . $value;
}



<pre class="highlight">
protected function _normalizeId($value)
{        
    // ... no hard coded prefix (@see ZF-10409)

    return parent::_normalizeId($value);
}

See also ZF-10409

Posted by Sebastian Kors (skors) on 2011-02-25T15:05:12.000+0000

Hi,

it's easy to use your own view helper which adds an id for example.

just create your own view helper class which extends Zend_View_Helper_Navigation_HelperAbstract or Zend_View_Helper_Navigation_Menu and overwrite or replace the mentioned parts.

use your own view helper as follows:

// in your view- or layout script navigation()->findHelper('Navigation\_MyOwnMenu')->myOwnMenu()->mySetIdMethod('mymenuid')->setUlClass('fancyclass') ; ?>

dont forget to add your library in application.ini for example, so it finds your own view helper.

Posted by Kai Uwe (kaiuwe) on 2011-05-26T10:39:59.000+0000

The patch fixes ZF-7212 and the subtask ZF-10409, because the new function for setting an ID uses the normalization of the ID attribute.

Posted by Rob Allen (rob) on 2012-05-29T20:11:10.000+0000

I can't get patch to apply to trunk.

Posted by Frank Brückner (frosch) on 2012-05-29T20:37:51.000+0000

Hi Rob, I will look into this and create a new patch.

Posted by Frank Brückner (frosch) on 2012-06-01T12:57:15.000+0000

New patch and more unit tests added.

Posted by Adam Lundrigan (adamlundrigan) on 2012-06-06T13:19:03.000+0000

Looks good to me...patches apply cleanly and all Navigation and View_Helper tests pass. As this changes the ID normalization, is there a test in place to ensure that the default normalization result is still the same as it was previously?

Posted by Frank Brückner (frosch) on 2012-06-06T15:14:34.000+0000

Hi Adam, yes: testSetPrefixForIdWithNull().

<pre class="highlight">
protected function _normalizeId($value)
{
    $prefix = get_class($this);
    $prefix = strtolower(trim(substr($prefix, strrpos($prefix, '_')), '_'));

    return $prefix . '-' . $value;
}



<pre class="highlight">
protected $_prefixForId = null;

protected $_skipPrefixForId = false;

public function getPrefixForId()
{
    if (null === $this->_prefixForId) {
        $prefix             = get_class($this);
        $this->_prefixForId = strtolower(
            trim(substr($prefix, strrpos($prefix, '_')), '_')
        ) . '-';
    }

    return $this->_prefixForId;
}

protected function _normalizeId($value)
{        
    if (false === $this->_skipPrefixForId) {
        $prefix = $this->getPrefixForId();
 
        if (strlen($prefix)) {
            return $prefix . $value;
        }
    }
    
    return parent::_normalizeId($value);
}

Posted by Rob Allen (rob) on 2012-06-13T19:55:24.000+0000

I can't get patch to apply cleaning. Adam, if you can, feel free to apply it.

Posted by Adam Lundrigan (adamlundrigan) on 2012-06-15T14:29:05.000+0000

Fixed in trunk (1.12.0): r24962

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts