Автор: Fabien Potencier (fabien@symfony.com)
Наследование: extends Sensio\Bundle\GeneratorBundle\Generator\Generator
 /**
  * @Route("/crud", name="_generator_crud")
  * @Template()
  */
 public function generateAction()
 {
     $request = $this->get('request');
     $crudEntity = new Crud();
     $form = $this->get('form.factory')->create(new GenerateCrudType(), $crudEntity);
     if ('POST' == $request->getMethod()) {
         $form->bindRequest($request);
         if ($form->isValid()) {
             $bundle = $this->get('kernel')->getBundle($crudEntity->bundle_name);
             $entityClass = $this->get('doctrine')->getEntityNamespace($crudEntity->bundle_name) . '\\' . $crudEntity->entity_name;
             $metadata = $this->getEntityMetadata($entityClass);
             $route_prefix = $this->getEntityMetadata($entityClass);
             $generator = new DoctrineCrudGenerator($this->get('filesystem'), $this->get('kernel')->locateResource('@SensioGeneratorBundle/Resources/skeleton/crud'));
             $generator->generate($bundle, $crudEntity->entity_name, $metadata[0], $crudEntity->format, $crudEntity->route_prefix, $crudEntity->with_write_action);
             $request->getSession()->setFlash('notice', sprintf("CRUD based on entity '%s' has been generated.", $crudEntity->entity_name));
             return new RedirectResponse($this->generateUrl('_generator'));
         }
     }
     return array('form' => $form->createView());
 }
 public function generate(BundleInterface $bundle, $entity, ClassMetadataInfo $metadata, $format, $routePrefix, $needWriteActions, $forceOverwrite)
 {
     parent::generate($bundle, $entity, $metadata, $format, $routePrefix, $needWriteActions, $forceOverwrite);
     try {
         $this->generateFormFilter($bundle, $entity, $metadata);
     } catch (\RuntimeException $e) {
         // form already exists
     }
     $dirFileConf = sprintf('%s/Resources/config/', $this->bundle->getPath());
     $this->generateConfAdminCrud($dirFileConf);
 }
Пример #3
0
 public function generate(BundleInterface $bundle, $entity, ClassMetadataInfo $metadata, $format, $routePrefix, $needWriteActions, $forceOverwrite)
 {
     parent::generate($bundle, $entity, $metadata, $format, $routePrefix, $needWriteActions, $forceOverwrite);
     $this->generateFormFilter($bundle, $entity, $metadata, $forceOverwrite);
 }
Пример #4
0
 public function getImportedResourceYamlKey($bundle, $prefix)
 {
     $snakeCasedBundleName = Container::underscore(substr($bundle, 0, -6));
     $routePrefix = DoctrineCrudGenerator::getRouteNamePrefix($prefix);
     return sprintf('%s%s%s', $snakeCasedBundleName, '' !== $routePrefix ? '_' : '', $routePrefix);
 }
 protected function getGenerator()
 {
     $generator = new DoctrineCrudGenerator($this->filesystem, $this->tmpDir);
     $generator->setSkeletonDirs(__DIR__ . '/../../Resources/skeleton');
     return $generator;
 }
 protected function generateShowView($dir)
 {
     parent::generateShowView($dir);
     $this->renderFile('crud/views/others/item.html.twig.twig', $dir . '/item.html.twig', array('bundle' => $this->bundle->getName(), 'entity' => $this->entity, 'identifier' => $this->metadata->identifier[0], 'fields' => $this->metadata->fieldMappings, 'actions' => $this->actions, 'route_prefix' => $this->routePrefix, 'route_name_prefix' => $this->routeNamePrefix));
 }
 protected function getTwigEnvironment()
 {
     $env = parent::getTwigEnvironment();
     $extension = $this->container->get('generator_bundle.twig_extension');
     $env->addExtension($extension);
     return $env;
 }