public function setupRoutes(Bundle $config, $controller, $pattern, $objectSection, Object $object, Object $relationObject = null, Field $relationField = null)
{
/** @var $importedRoutes \Symfony\Component\Routing\RouteCollection */
$importedRoutes = $this->import($controller, 'rest');
/** @var $route \Symfony\Component\Routing\Route */
foreach ($importedRoutes as $name => $route) {
$method = explode(':', $route->getDefault('_controller'))[1];
$routePattern = $route->getPath();
$route->setPath($pattern);
if ($relationObject) {
$this->setupObjectRouteRequirements($route, $relationObject, true);
}
$path = $route->getPath() . $routePattern;
$path = str_replace('.{_format}', '', $path);
$route->setPath($path);
$route->setDefault('_jarves_object_requirePk', !!strpos($routePattern, '{pk}'));
$this->setupObjectRouteRequirements($route, $object);
$route->setDefault('_jarves_object', $object->getKey());
$route->setDefault('_jarves_crud_definition', $object->getApiControllerDefinition());
$route->setDefault('_jarves_object_section', $objectSection);
$route->setDefault('_jarves_object_relation', $relationField ? $relationField->getId() : false);
$name = str_replace('/', '_', $pattern . $routePattern) . '_' . $method;
$name = str_replace(['{', '}'], '', $name);
$name = str_replace('%jarves_admin_prefix%_', 'jarves_', $name);
$this->routes->add($name, $route);
}
}