Details
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:
<div class="tagcloud">
<a class="10" href="http://localhost/aboutpixel">Code</a>
<a class="text-color-theme" href="">Zend Framework</a>
<a class="2" href="">PHP</a>
</div>
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)
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.