add missing parameters in node using url

This commit is contained in:
Simon Vieille 2021-03-24 20:36:51 +01:00
parent db4a163d54
commit b9784fec69
1 changed files with 16 additions and 0 deletions

View File

@ -83,11 +83,13 @@ class NodeEventSubscriber extends EntityManagerEventSubscriber
}
$parameters = $node->getParameters();
$routeParameters = [];
foreach ($parameters as $key => $parameter) {
$parameter['name'] = $this->routeParameterSlugify->slugify($parameter['name']);
$routeParameter = sprintf('{%s}', $parameter['name']);
$regex = '/'.preg_quote($routeParameter).'/';
$routeParameters[] = $parameter['name'];
if (!preg_match($regex, $generatedUrl)) {
$generatedUrl .= '/'.$routeParameter;
@ -96,6 +98,20 @@ class NodeEventSubscriber extends EntityManagerEventSubscriber
$parameters[$key] = $parameter;
}
preg_match_all('/\{(.*)\}/isU', $generatedUrl, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
if (!in_array($match[1], $routeParameters)) {
$parameters[] = [
'name' => $this->routeParameterSlugify->slugify($match[1]),
'defaultValue' => null,
'requirement' => null,
];
}
}
$generatedUrl = str_replace('//', '/', $generatedUrl);
$node->setParameters($parameters);
$attributes = $node->getAttributes();