deblan.tv/vendor/trinity/src/Trinity/.svn/pristine/61/6187574666f201276c1313ca29088834f7bc6e45.svn-base
2015-03-02 21:57:49 +01:00

47 lines
1.4 KiB
Plaintext

<?php
namespace Trinity\Bundle\AdminMenuBundle\Menu;
use Knp\Menu\Renderer\ListRenderer as BaseListRenderer;
use Knp\Menu\ItemInterface as BaseItemInterface;
class ListRenderer extends BaseListRenderer
{
protected function renderItem(BaseItemInterface $item, array $options)
{
$html = parent::renderItem($item, $options);
list($icon_src, $icon_attributes) = $item->getIcon();
if (!empty($icon_src)) {
if (!isset($icon_attributes['alt'])) {
$icon_attributes['alt'] = $item->getLabel();
}
if (!isset($icon_attributes['title'])) {
$icon_attributes['title'] = $item->getLabel();
}
$attributes = array();
foreach ($icon_attributes as $attribute => $value) {
$attributes[] = sprintf('%s="%s"', $attribute, str_replace('"', htmlentities('"'), $value));
}
$html = preg_replace(
'`<li([^>]*)>(.+)</li>`is',
sprintf('<li$1><img src="%s" %s /> $2</li>', $icon_src, implode(' ', $attributes)),
$html
);
}
if ($item->getLevel() < 2 ) {
$html = preg_replace('`<a href="([^"]+)">`sU', '<a data-target="$1" href="$1">', $html);
}
$html = preg_replace('`<li[^>]+>`', sprintf('<li>'), $html);
return $html;
}
}