本文整理汇总了PHP中Knp\Menu\ItemInterface类的典型用法代码示例。如果您正苦于以下问题:PHP ItemInterface类的具体用法?PHP ItemInterface怎么用?PHP ItemInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ItemInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setActive
/**
* Set active class to current item and all its parents (so it is automatically opened)
*
* @param ItemInterface $item
*/
protected function setActive(ItemInterface $item = null)
{
if ($item) {
$this->setActive($item->getParent());
$item->setAttribute('class', $item->getAttribute('class', '') . ' active');
}
}
示例2: createDropdownMenuItem
/**
* Create the dropdown menu.
*
* @param ItemInterface $rootItem
* @param string $title
* @param array $attributes
* @param string $caret
*
* @return \Knp\Menu\ItemInterface
*/
public function createDropdownMenuItem(ItemInterface $rootItem, $title, $attributes = [], $caret = true)
{
// Add child to dropdown, still normal KnpMenu usage
$options = array_merge(['dropdown' => true, 'childrenAttributes' => ['class' => 'vic-dropdown-menu'], 'attributes' => ['class' => 'vic-dropdown', 'data-toggle' => 'vic-dropdown'], 'linkAttributes' => ['class' => 'vic-dropdown-toggle', 'data-toggle' => 'vic-dropdown'], 'uri' => '#'], $attributes);
$menu = $rootItem->addChild($title, $options)->setExtra('caret', $caret);
return $menu;
}
示例3: configureSideMenu
/**
* @param MenuItemInterface $menu
* @param $action
* @param AdminInterface $childAdmin
*/
protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
{
$pool = $this->container->get('sonata.admin.pool');
$adminGroups = $pool->getAdminGroups();
foreach ($adminGroups as $name => $adminGroup) {
if (isset($adminGroup['items'])) {
foreach ($adminGroup['items'] as $key => $id) {
$admin = $pool->getInstance($id);
if ($admin->showIn(Admin::CONTEXT_DASHBOARD)) {
$groups[$name]['items'][$key] = $admin;
} else {
unset($groups[$name]['items'][$key]);
}
}
}
if (empty($groups[$name]['items'])) {
unset($groups[$name]);
}
}
$menu->addChild($this->trans('dashboard', [], 'admin'), array('uri' => $this->getRouteGenerator()->generate('sonata_admin_dashboard'), 'attributes' => array('class' => 'home')));
foreach ($groups as $name => $group) {
$parent = $menu->addChild('header_' . $this->trans($name), array('label' => $this->trans($name), 'attributes' => array('class' => 'submenu')));
foreach ($group['items'] as $key => $admin) {
$item = $parent->addChild($this->trans($admin->getLabel()), array('uri' => $admin->generateUrl('list')));
if (get_class($this) == get_class($admin)) {
$parent[$this->trans($admin->getLabel())]->setCurrent(true);
//$item['header_'.$this->trans($name)]->setAttributes(array('class' => 'submenu open'));
}
}
}
}
示例4: configureSideMenu
protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
{
if (!in_array($action, array('edit', 'create'))) {
return;
}
$id = $this->getRequest()->get('id');
$vars = $menu->addChild('Variables', array('route' => 'tsk_contract_default_variables', 'attr' => array('onclick' => 'alert("foo"); return false;')));
$contract = $vars->addChild('Contract');
$contract->addChild('getAmount');
$contract->addChild('getProgram');
$contract->addChild('getExpireDate');
$contract->addChild('getRolloverTokens');
$contract->addChild('getContractNumTokens');
$contract->addChild('getProgramLegalDescription');
$student = $vars->addChild('Student');
$student->addChild('getContact.getFirstName');
$student->addChild('getContact.getLastName');
$student->addChild('getContact.getAddress1');
$student->addChild('getContact.getAddress2');
$student->addChild('getContact.getCity');
$student->addChild('getContact.getState');
$student->addChild('getContact.getPostalcode');
$student->addChild('getContact.getPhone');
$school = $vars->addChild('School');
$school->addChild('getContact.getState');
$org = $vars->addChild('Org');
$org->addChild('getName');
}
示例5: matchItem
/**
* @param ItemInterface $item
*
* @return bool|null
*/
public function matchItem(ItemInterface $item)
{
if (null === $this->getRequest()) {
return null;
}
$route = $this->getRequest()->attributes->get('_route');
$routeParameters = $this->getRequest()->attributes->get('_route_params');
if (null === $route) {
return null;
}
$routes = (array) $item->getExtra('routes', array());
foreach ($routes as $testedRoute) {
if ($route == $testedRoute['route']) {
if (is_array($routeParameters) && 0 < count($routeParameters)) {
if (isset($testedRoute['parameters']) && is_array($testedRoute['parameters'])) {
$matching = true;
foreach ($routeParameters as $index => $value) {
if ('_' != substr($index, 0, 1)) {
if (!isset($testedRoute['parameters'][$index]) || ($testedRoute['parameters'][$index] != $value && 0 < $testedRoute['parameters'][$index] || !is_numeric($value))) {
$matching = false;
}
}
}
if ($matching) {
return true;
}
}
} else {
return true;
}
}
}
return null;
}
示例6: matchItem
/**
* {@inheritDoc}
*/
public function matchItem(ItemInterface $item)
{
if ($item->getUri() === $this->getRequestUri()) {
return true;
}
return null;
}
示例7: addChildNodes
private function addChildNodes(ItemInterface $menu, MenuItem $menuItem)
{
$child = $menu->addChild($menuItem->getName(), $this->createMenuOptions($menuItem));
foreach ($menuItem->getChildren() as $childItem) {
$this->addChildNodes($child, $childItem);
}
}
示例8: addConfigurationMenu
/**
* @param ItemInterface $menu
*/
private function addConfigurationMenu(ItemInterface $menu)
{
$child = $menu->addChild('configuration')->setLabel('sylius.menu.admin.main.configuration.header');
if (!$child->hasChildren()) {
$menu->removeChild('configuration');
}
}
示例9: configureTabMenu
/**
* @throws InvalidConfigurationException
*/
public function configureTabMenu(AdminInterface $admin, MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
{
if (!($subject = $admin->getSubject())) {
return;
}
if (!$subject instanceof RouteReferrersReadInterface && !$subject instanceof Route) {
throw new InvalidConfigurationException(sprintf('%s can only be used on subjects which implement Symfony\\Cmf\\Component\\Routing\\RouteReferrersReadInterface or Symfony\\Component\\Routing\\Route.', __CLASS__));
}
if ($subject instanceof PrefixInterface && !is_string($subject->getId())) {
// we have an unpersisted dynamic route
return;
}
$defaults = array();
if ($subject instanceof TranslatableInterface) {
if ($locale = $subject->getLocale()) {
$defaults['_locale'] = $locale;
}
}
try {
$uri = $this->router->generate($subject, $defaults);
} catch (RoutingExceptionInterface $e) {
// we have no valid route
return;
}
$menu->addChild($this->translator->trans('admin.menu_frontend_link_caption', array(), 'CmfRoutingBundle'), array('uri' => $uri, 'attributes' => array('class' => 'sonata-admin-menu-item', 'role' => 'menuitem'), 'linkAttributes' => array('class' => 'sonata-admin-frontend-link', 'role' => 'button', 'target' => '_blank', 'title' => $this->translator->trans('admin.menu_frontend_link_title', array(), 'CmfRoutingBundle'))));
}
示例10: matchItem
/**
* {@inheritdoc}
*/
public function matchItem(ItemInterface $item)
{
if (($page = $this->getPage()) && $page->getId() !== null) {
return $item->getExtra('_page_id', null) === $page->getId();
}
return;
}
示例11: matchItem
/**
* Checks whether an item is current.
*
* If the voter is not able to determine a result,
* it should return null to let other voters do the job.
*
* @param \Knp\Menu\ItemInterface $item The item
*
* @return boolean|null
*/
public function matchItem(ItemInterface $item)
{
if ($item->getUri() === $this->container->get('request')->getRequestUri()) {
return true;
}
return false;
}
示例12: buildCategoryMenu
/**
* @param \Knp\Menu\ItemInterface $menu The item to fill with $routes
* @param array $options The item options
* @param string $currentUri The current URI
*/
public function buildCategoryMenu(ItemInterface $menu, array $options = array(), $currentUri = null)
{
//$categories = $this->categoryManager->getCategoryTree();
//$this->fillMenu($menu, $categories, $options, $currentUri);
$menu->addChild('home', array('route' => 'home'));
$menu->addChild('home2', array('route' => 'home'));
}
示例13: matchItem
public function matchItem(ItemInterface $item)
{
if (null === $this->request) {
return null;
}
$route = $this->request->attributes->get('_route');
if (null === $route) {
return null;
}
$routes = (array) $item->getExtra('routes', array());
$parameters = (array) $item->getExtra('routesParameters', array());
foreach ($routes as $testedRoute) {
if (is_string($testedRoute)) {
$testedRoute = array('route' => $testedRoute);
// BC layer for the configuration of route params
if (isset($parameters[$testedRoute['route']])) {
$testedRoute['parameters'] = $parameters[$testedRoute['route']];
trigger_error('Using the routeParameters extra is deprecated. The parameters should be passed along the route.', E_USER_DEPRECATED);
}
}
if (!is_array($testedRoute)) {
throw new \InvalidArgumentException('Routes extra items must be strings or arrays.');
}
if ($this->isMatchingRoute($testedRoute)) {
return true;
}
}
return null;
}
示例14: addUserMenu
protected function addUserMenu(ItemInterface $menu)
{
$menu->addChild('User', array('uri' => '#', 'label' => sprintf('<i class="fa fa-shield"></i> <span>%s</span><i class="fa fa-angle-double-left pull-right"></i></a>', $this->translator->trans('menu.user.title', array(), $this->translationDomain)), 'extras' => array('safe_label' => true), 'attributes' => array('class' => 'treeview')));
$menu['User']->setChildrenAttribute('class', 'treeview-menu');
$menu['User']->addChild('Add', array('label' => $this->translator->trans('menu.user.add', array(), $this->translationDomain), 'route' => 'symfonian_indonesia_admin_security_user_new', 'attributes' => array('class' => 'treeview')));
$menu['User']->addChild('List', array('label' => $this->translator->trans('menu.user.list', array(), $this->translationDomain), 'route' => 'symfonian_indonesia_admin_security_user_list', 'attributes' => array('class' => 'treeview')));
}
示例15: build
/**
* {@inheritDoc}
*/
public function build(ItemInterface $menu, array $options = array(), $alias = null)
{
if (!$this->componentRegistry->hasAllowedProcessor()) {
return;
}
$menu->addChild('orob2b.product.frontend.quick_add.title', ['route' => 'orob2b_product_frontend_quick_add', 'extras' => ['position' => 500, 'description' => 'orob2b.product.frontend.quick_add.description']]);
}