public function getRoutePath(array &$requirements_entitys, array &$requirements, array &$requirement_keys, \Symforce\AdminBundle\Compiler\Generator\PhpWriter $generator, \Symforce\AdminBundle\Compiler\Generator\PhpWriter $dispatcher, $with_entity, $path, $break_requirement_key = null, $first_entity_call = true) { $entity_object_name = '$' . $this->admin_name; if ($with_entity) { $requirements_entitys[$this->admin_class] = $this->eneity_id_name; if ($this->admin->getPropertySlugName()) { if ($this->admin->isPropertySlugNullable()) { $requirements[$this->eneity_id_name] = '\\w*'; } else { $requirements[$this->eneity_id_name] = '\\w+'; } } else { $requirements[$this->eneity_id_name] = '\\d+'; } $property_slug_name = $this->admin->getPropertyIdName(); $property_id_name = $this->admin->getPropertySlugName(); if (!empty($property_slug_name)) { $generator->writeln(sprintf('$options["%s"] = $accessor->getValue(%s, "%s");', $this->eneity_id_name, $entity_object_name, $property_slug_name)); $generator->writeln(sprintf('if( empty($options["%s"]) ) $options["%s"] = $accessor->getValue(%s, "%s");', $this->eneity_id_name, $this->eneity_id_name, $entity_object_name, $property_id_name)); } else { $generator->writeln(sprintf('$options["%s"] = $accessor->getValue(%s, "%s");', $this->eneity_id_name, $entity_object_name, $property_id_name)); } if ($first_entity_call) { $first_entity_call = false; $dispatcher->writeln(sprintf('%s = $controller->getPageObject("%s", $request->get("%s") );', $entity_object_name, $this->admin_name, $this->eneity_id_name)); } else { $dispatcher->writeln(sprintf('$controller->setPageObject(%s, "%s", $request->get("%s") );', $entity_object_name, $this->admin_name, $this->eneity_id_name)); } } if (!$first_entity_call) { if (!isset($requirement_keys[$this->eneity_id_name])) { if ($break_requirement_key) { if ($with_entity) { $path = '/' . $this->route_path . '/' . '{' . $this->eneity_id_name . '}' . $path; } else { $path = '/' . $this->route_path . $path; } } } else { if ($break_requirement_key) { // throw new \Exception(sprintf("%s: `{%s}` duplicate, maybe you missing `{%s}` in path `%s`", $this->err_msg, $this->eneity_id_name, $break_requirement_key, $path )); } } } if ($this->page_parent_entity) { $parent_entity_object_name = '$' . $this->parent_admin->getName(); if ($with_entity) { $generator->writeln(sprintf('%s = $accessor->getValue(%s, "%s");', $parent_entity_object_name, $entity_object_name, $this->property_page_name)); } $parent_generator = $this->page_loader->getPageGeneratorByClass($this->page_parent_entity); if (!$first_entity_call) { $dispatcher->writeln(sprintf('%s = $accessor->getValue(%s, "%s");', $parent_entity_object_name, $entity_object_name, $this->property_page_name)); } if (!$break_requirement_key && !isset($requirement_keys[$this->eneity_id_name])) { $break_requirement_key = $this->eneity_id_name; } $path = $parent_generator->getRoutePath($requirements_entitys, $requirements, $requirement_keys, $generator, $dispatcher, true, $path, $break_requirement_key, $first_entity_call); } return $path; }
public function generateRouteGenerator(\Symforce\AdminBundle\Compiler\Generator\PhpWriter $generator, $use_object, $is_first = false) { $admin_name = $this->admin->getName(); $route_parent = $this->admin->getRouteParent(); if ($route_parent) { if ($is_first) { $generator->writeln(sprintf('$%s = $loader->getAdminByClass("%s");', $admin_name, $this->admin->getClassName())); $generator->writeln(sprintf('$_sf_admin_route_parameters = $%s->getRouteParameters();', $admin_name)); } $route_parent_name = $route_parent->getName(); $parent_property = $this->admin->getRouteParentProperty(); $generator->writeln(sprintf('if( !isset($options["%s_id"] )) {', $route_parent_name))->indent(); if ($use_object) { $generator->writeln(sprintf('$%s_object = $%s_object ? $accessor->getValue($%s_object, "%s") : null ;', $route_parent_name, $admin_name, $admin_name, $parent_property))->writeln(sprintf('if( $%s_object ) {', $route_parent_name))->indent()->writeln(sprintf('$options["%s_id"] = $accessor->getValue($%s_object, "%s") ;', $route_parent_name, $route_parent_name, $route_parent->getPropertyIdName()))->outdent()->writeln(sprintf('} else if( isset($_sf_admin_route_parameters["%s_id"] )) {', $route_parent_name))->indent()->writeln(sprintf('$options["%s_id"] = $_sf_admin_route_parameters["%s_id"] ;', $route_parent_name, $route_parent_name))->outdent()->writeln('} else {')->indent()->writeln(sprintf(' $options["%s_id"] = $loader->getAdminByClass("%s")->getRouteObjectId() ;', $route_parent_name, $route_parent->getClassName()))->outdent()->writeln('}'); } else { $generator->writeln(sprintf('if( isset($_sf_admin_route_parameters["%s_id"] )) {', $route_parent_name))->indent()->writeln(sprintf(' $options["%s_id"] = $_sf_admin_route_parameters["%s_id"] ;', $route_parent_name, $route_parent_name))->outdent()->writeln('} else {')->indent()->writeln(sprintf(' $options["%s_id"] = $loader->getAdminByClass("%s")->getRouteObjectId() ;', $route_parent_name, $route_parent->getClassName()))->outdent()->writeln('} '); } $generator->outdent()->writeln('}'); $route_parent_generator = $this->loader->getAdminRouteGenerator($route_parent_name); $route_parent_generator->generateRouteGenerator($generator, $use_object); } }