本文整理汇总了PHP中Knp\Menu\ItemInterface::getExtra方法的典型用法代码示例。如果您正苦于以下问题:PHP ItemInterface::getExtra方法的具体用法?PHP ItemInterface::getExtra怎么用?PHP ItemInterface::getExtra使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Knp\Menu\ItemInterface
的用法示例。
在下文中一共展示了ItemInterface::getExtra方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: menuSort
/**
* Sort the menu based on weight
*
* @param ItemInterface $menuItemA
* @param ItemInterface $menuItemB
*
* @return int
*/
public static function menuSort(ItemInterface $menuItemA, ItemInterface $menuItemB)
{
if ($menuItemA->getExtra('weight') == $menuItemB->getExtra('weight')) {
return 0;
}
return $menuItemA->getExtra('weight') < $menuItemB->getExtra('weight') ? -1 : 1;
}
示例2: 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;
}
示例3: 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 ItemInterface $item
*
* @return boolean|null
*/
public function matchItem(ItemInterface $item)
{
if ($item->getExtra('link', false) && $this->parentControl) {
$presenter = $this->parentControl->getPresenter(true);
$item->setCurrent(call_user_func_array(array($presenter, 'isLinkCurrent'), $item->getExtra('link')));
return $item->isCurrent();
}
return null;
}
示例4: renderLabel
/**
* unless 'raw' extra isn't set to true, we try to translate the label.
*
* @param ItemInterface $item
* @param array $options
*
* @return string
*/
protected function renderLabel(ItemInterface $item, array $options)
{
if ($options['allow_safe_labels'] && $item->getExtra('safe_label', false)) {
return $item->getLabel();
}
if ($item->getExtra('raw', false) !== false) {
return $this->escape($item->getLabel());
}
return $this->escape(trans($item->getLabel()));
}
示例5: addNavLinkRoute
protected function addNavLinkRoute(ItemInterface $menu, $label, $route, $routeParameters = array())
{
$item = $menu->addChild($label, array('route' => $route, 'routeParameters' => $routeParameters));
$item->setExtra('translation_domain', $menu->getExtra('translation_domain'));
$menu->setExtra('request_uri', $menu->getExtra('request_uri'));
if ($item->getUri() == $menu->getExtra('request_uri')) {
$item->setAttribute('class', 'active');
}
return $item;
}
示例6: 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 ItemInterface $item
* @return boolean|null
*/
public function matchItem(ItemInterface $item)
{
/* @var $request \Symfony\Component\HttpFoundation\Request */
$request = $this->container->get('request');
if ($item->getUri() === $request->getRequestUri()) {
return true;
}
if ($item->getExtra('routes') !== null && in_array($request->attributes->get('_route'), $item->getExtra('routes'))) {
return true;
}
return null;
}
示例7: addHiddenItems
/**
* @param ItemInterface $parent
* @param array $routes
* @param string|null $basePath
*/
public static function addHiddenItems($parent, $routes, $basePath = null)
{
$parent->setDisplayChildren(false);
if (null === $basePath && null !== $parent->getExtra('routes') && isset($parent->getExtra('routes')[0]['route'])) {
$basePathArray = explode("_", $parent->getExtra('routes')[0]['route']);
$basePathArray[count($basePathArray) - 1] = '%s';
$basePath = implode("_", $basePathArray);
}
foreach ($routes as $routeIndex => $routeParameters) {
$route = sprintf($basePath, $routeIndex);
$parent->addChild($route, ['route' => $route, 'routeParameters' => $routeParameters]);
}
}
示例8: matchItem
/**
* {@inheritdoc}
*/
public function matchItem(ItemInterface $item)
{
$admin = $item->getExtra('admin');
$match = null;
if ($admin instanceof AdminInterface && $admin->hasRoute('list') && $admin->isGranted('LIST') && $this->request && $this->request->get('_sonata_admin') == $admin->getCode()) {
$match = true;
}
$route = $item->getExtra('route');
if ($route && $this->request && $route == $this->request->get('_route')) {
$match = true;
}
return $match;
}
示例9: matchItem
/**
* {@inheritdoc}
*/
public function matchItem(ItemInterface $item)
{
if (($page = $this->getPage()) && $page->getId() !== null) {
return $item->getExtra('_page_id', null) === $page->getId();
}
return;
}
示例10: 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;
}
示例11: modifyItem
protected function modifyItem(ItemInterface $item, array $options)
{
if (!$item->getExtra('remove_leaf', false)) {
return;
}
if (!$item->hasChildren()) {
$this->removeItem($item);
}
}
示例12: decorate
public function decorate(KnpMenuItem $knpMenuItem, AdminMenuItem $adminMenuItem)
{
if ($adminMenuItem instanceof RoutableItem && $adminMenuItem->getRoute()) {
$knpMenuItem->setUri($this->router->generate($adminMenuItem->getRoute(), $adminMenuItem->getRouteParameters()));
$routes = $knpMenuItem->getExtra('routes', array());
$routes[] = array('route' => $adminMenuItem->getRoute(), 'parameters' => $adminMenuItem->getRouteParameters());
$knpMenuItem->setExtra('routes', $routes);
}
}
示例13: matchItem
/**
* {@inheritDoc}
*/
public function matchItem(ItemInterface $item)
{
if ($prefix = $item->getExtra('prefix_match', $this->defaultActive)) {
if (strpos($this->getRequestUri(), $item->getUri()) === 0) {
return true;
}
}
return null;
}
示例14: matchItem
/**
* {@inheritDoc}
*/
public function matchItem(ItemInterface $item = null)
{
if (!$this->request) {
return null;
}
$content = $item->getExtra('content');
if (null !== $content && $this->request->attributes->has($this->requestKey) && $this->request->attributes->get($this->requestKey) instanceof $this->childClass && $this->request->attributes->get($this->requestKey)->getParentDocument() === $content) {
return true;
}
return null;
}
示例15: decorate
public function decorate(KnpMenuItem $knpMenuItem, AdminMenuItem $adminMenuItem)
{
if ($adminMenuItem instanceof ElementItem && $adminMenuItem->hasOption('elements')) {
$routes = $knpMenuItem->getExtra('routes', array());
/** @var Element $element */
foreach ($adminMenuItem->getOption('elements') as $element) {
$routes[] = array('route' => $element->getRoute(), 'parameters' => $element->getRouteParameters());
}
$knpMenuItem->setExtra('routes', $routes);
}
}