47 lines
1.4 KiB
Plaintext
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;
|
|
}
|
|
}
|