public function generateActionPath(\Symforce\AdminBundle\Compiler\Cache\ActionCache $action, \Symfony\Component\Routing\RouteCollection $route_admin_collection) { $class = $this->loader->getCompileClass(); $writer = $this->loader->getCompileAdminWriter(); $route_name = $action->getAdminRouteName(); $admin_name = $this->admin->getName(); $admin_class = $this->admin->getClassName(); $generator = new \Symforce\AdminBundle\Compiler\Generator\PhpWriter(); $dispatcher = new \Symforce\AdminBundle\Compiler\Generator\PhpWriter(); $requirement = array(); $generator->write('function(PropertyAccessorInterface $accessor, AdminLoader $loader, '); if ($action->isRequestObject()) { $generator->write(sprintf('%s $%s_object, ', '\\' . $admin_class, $admin_name)); } $generator->writeln('array $options = array()){')->indent(); $dispatcher->writeln('function(AdminLoader $loader, Request $request){')->indent(); $dispatcher->writeln(sprintf('$loader->setRouteAdminAction("%s", "%s");', $admin_name, $action->getName())); $dispatcher->writeln('$_sf_admin_route_parameters = array();'); $dispatcher->writeln('$_sf_admin_route_parents = array();'); $path = array(); $route_generator_parents = array(); $this->getRoutePatentGenerator($route_generator_parents); foreach ($route_generator_parents as $route_parent_generator) { $route_parent_generator->generateRouteDispatcher($dispatcher, $requirement, $path); } $dispatcher->writeln(sprintf('$%s = $loader->getAdminByClass("%s");', $admin_name, $admin_class)); $dispatcher->writeln(sprintf('$%s->setRouteParameters($_sf_admin_route_parameters);', $admin_name)); $dispatcher->writeln(sprintf('$%s->setRouteParents($_sf_admin_route_parents);', $admin_name)); $route_parent = $this->admin->getRouteParent(); if ($route_parent) { $admin_name = $this->admin->getName(); $dispatcher->writeln(sprintf('$%s->setRouteParent($%s);', $admin_name, $route_parent->getName())); $dispatcher->writeln(sprintf('$%s->setRouteParentProperty("%s");', $admin_name, $this->admin->getRouteParentProperty())); } if ($action->isRequestObject()) { $dispatcher->writeln(sprintf('$%s->setRouteObjectId( $request->get("%s_id") );', $admin_name, $admin_name)); } $dispatcher->writeln(sprintf('$action = $%s->getAction("%s");', $admin_name, $action->getName())); if ($action->isRequestObject()) { $generator->writeln(sprintf('$options["%s_id"] = $accessor->getValue($%s_object, "%s") ;', $admin_name, $admin_name, $this->admin->getPropertyIdName())); } $this->generateRouteGenerator($generator, $action->isRequestObject(), true); if ($route_parent) { $route_parent_renerator = $this->loader->getAdminRouteGenerator($route_parent->getName()); if (!$route_parent_renerator->isSingleChild($this->admin_name)) { $path[] = 'of_' . $this->admin->getRouteParentProperty(); } } $path[] = $admin_name; if ($this->admin->tree) { $id = 'sf_admin_tree_parent'; $requirement[$id] = '\\d+'; $generator->writeln(sprintf('if( !isset($options["%s"]) ) $options["%s"] = 0;', $id, $id)); $path[] = sprintf('{%s}', $id); $dispatcher->writeln(sprintf('$%s->setTreeObjectId( $request->get("%s") );', $admin_name, $id)); } if ($this->admin->workflow) { $id = 'admin_route_workflow'; $requirement[$id] = '\\w+'; $path[] = sprintf('{%s}', $id); $dispatcher->writeln(sprintf('$%s->setRouteWorkflow( $request->get("%s") );', $admin_name, $id)); $generator->writeln(sprintf('if( !isset($options["%s"]) ) $options["%s"] = $loader->getAdminByClass("%s")->getRouteWorkflow();', $id, $id, $admin_class)); } $owner = self::getPropertyValue($this->admin, 'property_owner_name'); if ($owner) { $id = 'admin_route_owner_identity'; $requirement[$id] = '\\w+'; $path[] = sprintf('{%s}', $id); $dispatcher->writeln(sprintf('$%s->setRouteOwnerIdentity( $request->get("%s") );', $admin_name, $id)); $generator->writeln(sprintf('if( !isset($options["%s"]) ) $options["%s"] = $loader->getAdminByClass("%s")->getRouteOwnerIdentity();', $id, $id, $admin_class)); $id = 'admin_route_owner_id'; $requirement[$id] = '\\d+'; $path[] = sprintf('{%s}', $id); $dispatcher->writeln(sprintf('$%s->setRouteOwnerId( $request->get("%s") );', $admin_name, $id)); $generator->writeln(sprintf('if( !isset($options["%s"]) ) $options["%s"] = $loader->getAdminByClass("%s")->getRouteOwnerId();', $id, $id, $admin_class)); } $path[] = $action->getName(); if ($action->isRequestObject()) { $path[] = sprintf('{%s_id}', $admin_name); } if ($action->isListAction()) { $id = 'admin_list_page'; $requirement[$id] = '\\d+'; $generator->writeln(sprintf('if( !isset($options["%s"]) ) $options["%s"] = 1;', $id, $id)); $path[] = sprintf('{%s}.html', $id); $dispatcher->writeln(sprintf('$action->setPageNumber( $request->get("%s") );', $id)); } $path = '/' . join('/', $path); $route_config = array('_controller' => 'Symforce\\AdminBundle\\Controller\\AdminController::adminAction', '_sf_route_name' => $route_name); $route = new \Symfony\Component\Routing\Route($path, $route_config, $requirement); $route_admin_collection->add($route_name, $route); $dispatcher->writeln('return $action;'); $generator->writeln(sprintf('// path = %s ', $path)); $generator->writeln('return $options;'); $writer->write(sprintf('$this->admin["%s"]["generator"] = ', $route_name))->indent()->write($generator->getContent())->outdent()->writeln("};"); $writer->write(sprintf('$this->admin["%s"]["dispatcher"] = ', $route_name))->indent()->write($dispatcher->getContent())->outdent()->writeln('};'); }
public function afterCreate(Controller $controller, Request $request, ActionCache $action, $object, \Symfony\Component\Form\Form $form) { $request->getSession()->getFlashBag()->add('info', $this->trans('sf.action.create.finish', $object)); return $controller->redirect($action->getFormReferer($form)); }