Skip to content

Commit

Permalink
fix FormType and FormFilterType in the Form directory are never overw…
Browse files Browse the repository at this point in the history
…ritten
  • Loading branch information
jordillonch committed Mar 7, 2014
1 parent 5444699 commit 6b8d6fa
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Generator/JordiLlonchCrudGenerator.php
Expand Up @@ -24,21 +24,20 @@ public function generate(BundleInterface $bundle, $entity, ClassMetadataInfo $me
{
parent::generate($bundle, $entity, $metadata, $format, $routePrefix, $needWriteActions, $forceOverwrite);

try {
$this->generateFormFilter($bundle, $entity, $metadata);
} catch (\RuntimeException $e ) {
// form already exists
}
$this->generateFormFilter($bundle, $entity, $metadata, $forceOverwrite);
}

/**
* Generates the entity form class if it does not exist.
*
* @param BundleInterface $bundle The bundle in which to create the class
* @param string $entity The entity relative class name
* @param BundleInterface $bundle The bundle in which to create the class
* @param string $entity The entity relative class name
* @param ClassMetadataInfo $metadata The entity metadata class
* @param $forceOverwrite
*
* @throws \RuntimeException
*/
public function generateFormFilter(BundleInterface $bundle, $entity, ClassMetadataInfo $metadata)
public function generateFormFilter(BundleInterface $bundle, $entity, ClassMetadataInfo $metadata, $forceOverwrite)
{
$parts = explode('\\', $entity);
$entityClass = array_pop($parts);
Expand All @@ -47,7 +46,7 @@ public function generateFormFilter(BundleInterface $bundle, $entity, ClassMetada
$dirPath = $bundle->getPath().'/Form';
$this->classPath = $dirPath.'/'.str_replace('\\', '/', $entity).'FilterType.php';

if (file_exists($this->classPath)) {
if (!$forceOverwrite && file_exists($this->classPath)) {
throw new \RuntimeException(sprintf('Unable to generate the %s form class as it already exists under the %s file', $this->className, $this->classPath));
}

Expand Down

0 comments on commit 6b8d6fa

Please sign in to comment.