ZF-6578: Zend_Tag: Bug in Zend_Tag_Cloud_Decorator_HtmlTag->setClassList()

Description

When using Zend_Tag_Cloud_Decorator_HtmlTag->setClassList(), instead of assigning the className, I'm getting the weightValue of a Zend_Tag_Item.

I have this code in my viewscript:

// Create the item list $list = new Zend_Tag_ItemList();

// Assign tags to it $list[] = new Zend_Tag_Item(array('title' => 'Code', 'weight' => 50, 'params' => array('url' => WEBHOST))); $list[] = new Zend_Tag_Item(array('title' => 'Zend Framework', 'weight' => 1)); $list[] = new Zend_Tag_Item(array('title' => 'PHP', 'weight' => 5));

// Spread absolute values on the items $list->spreadWeightValues(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));

$cloud = new Zend_Tag_Cloud(); $cloud->setItemList($list); // Cloud-Decorator $cloudDecorator = new Zend_Tag_Cloud_Decorator_HtmlCloud(); $cloudDecorator->setHtmlTags(array('div' => array('class' => 'tagcloud'))); $cloud->setCloudDecorator($cloudDecorator); // Tag-Decorator $tagDecorator = new Zend_Tag_Cloud_Decorator_HtmlTag(); $tagDecorator->setHtmlTags(array()); $tagDecorator->setMaxFontSize(26); $tagDecorator->setMinFontSize(10); $tagDecorator->setFontSizeUnit('px'); $tagDecorator->setClassList(array('text-color-theme')); $cloud->setTagDecorator($tagDecorator);

By using $tagDecorator->setClassList(array('text-color-theme')); I get this html-code:

As you see, the second a-tag is correct, but the other two have numbers as classNames.

I tracked it down to Zend\Tag\Cloud\Decorator\HtmlTag.php in Line 251, where the className should be assigned, not the weightValue.

Here is a var_dump of one tag-item:

object(Zend_Tag_Item)[434] protected '_title' => string 'Code' (length=4) protected '_weight' => float 50 protected '_params' => array 'url' => string 'http://localhost/testpage' (length=27) 'weightValue' => int 10 protected '_skipOptions' => array 0 => string 'options' (length=7) 1 => string 'param' (length=5)

Comments

This is actually no bug of the decorator but of Zend_Tag_ItemList. I currently generates a "division by zero"-warning when just a single value is supplied. By the way:

a) you don't have to spread weight values yourself when using a standard decorator b) When you set font-size settings first and then a class list, the font size settings are overriden.

Thanks for the fix.

But isn't what you wrote to b) in your comment another bug?

I know that font-size settings are overwritten by setClassList(), but exactly the same happens vice versa. That means, I can either set font-size settings without being able to set classes (example 1), or I can use classes overwriting my font-size settings (example 2). :(

example 1 $tagDecorator->setClassList(array('text-color-theme')); $tagDecorator->setMaxFontSize(26); $tagDecorator->setMinFontSize(10); $tagDecorator->setFontSizeUnit('px');

example 2 $tagDecorator->setMaxFontSize(26); $tagDecorator->setMinFontSize(10); $tagDecorator->setFontSizeUnit('px'); $tagDecorator->setClassList(array('text-color-theme'));

Or did I miss something?

Yes, you are missing the fact, that it is about spreading either font-sizes or css-classes for the relative values ;)