Comments (7)
Your patter is not a valid regexp.
from knpmenu.
What is wrong with the regexp?
However I think the issue persists.
from knpmenu.
When building the item as described above, \Knp\Menu\Integration\Symfony\RoutingExtension::buildOptions
will add the route
to the extras item.
The issue is in the following code in \Knp\Menu\Matcher\Voter\RouteVoter::matchItem
:
$routes = (array) $item->getExtra('routes', []);
// $routes is now [ pattern="my_route.*", 0 = [ route = "my_route", parameters= []]
foreach ($routes as $testedRoute) {
// in the first iteration, $testedRoute is "my_reoute.*"
if (\is_string($testedRoute)) {
// this will be true in the first iteration, thus the pattern
// will be passed to isMatchingRoute as a route
$testedRoute = ['route' => $testedRoute];
}
if (!\is_array($testedRoute)) {
throw new \InvalidArgumentException('Routes extra items must be strings or arrays.');
}
if ($this->isMatchingRoute($request, $testedRoute)) {
return true;
}
}
Subsequently in \Knp\Menu\Matcher\Voter\RouteVoter::isMatchingRoutethe pattern is never tested because
$testedRoute['route']` is always set.
private function isMatchingRoute(Request $request, array $testedRoute): bool
{
$route = $request->attributes->get('_route');
if (isset($testedRoute['route'])) {
if ($route !== $testedRoute['route']) {
return false;
}
} elseif (!empty($testedRoute['pattern'])) {
if (!\preg_match($testedRoute['pattern'], $route)) {
return false;
}
from knpmenu.
Above pull request will make a menu item with a pattern functional as below functional again:
$menu->addChild('Location', [
'route' => 'location_index',
'extras' => [
'routes' => [
'pattern' => '/location.*/'
]
]
]);
(of course I forgot the slashes for the regex in my first comment)
from knpmenu.
Ah no, I found the issue. routes
takes a list of routes to match, which can be either a string (for the shortcut case) or an associative array. Your config misses a level of array.
from knpmenu.
Compare your config with the the example you linked in the description.
from knpmenu.
Thanks 👍 , didn't spot that. This works now.
from knpmenu.
Related Issues (20)
- Allow Twig 3 HOT 3
- LazyProvider must be compatible with ... HOT 4
- Documentation HOT 1
- Label with hierarchical numbering 1.2.2.1
- Apply "currentClass" in link in item HOT 2
- Change description HOT 4
- Add template for boostrap 4 etc.? HOT 3
- request attribute voter HOT 3
- Drop support for PHP 7.3? HOT 3
- Change \Knp\Menu\MenuFactory::getExtension to protected instead of private! HOT 4
- Matcher::addVoter() method undefined HOT 3
- Suggesting some configurations
- Add support for symfony 6.1 HOT 2
- What about PHP8.1 support? HOT 2
- Drop PHP 7 HOT 1
- Add ability to add items to menus in a sorted way HOT 1
- Document ESI usage
- Support Symfony 7
- getting the actual label, not the label ?? name HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from knpmenu.