Skip to content

Instantly share code, notes, and snippets.

@pborreli
Created September 14, 2010 18:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pborreli/579519 to your computer and use it in GitHub Desktop.
Save pborreli/579519 to your computer and use it in GitHub Desktop.
how to remove "with_empty" checkbox for all generated formFilters in symfony 1.4
<?php
class xxxConfiguration extends sfXxxConfiguration
{
public function setup()
{
$this->dispatcher->connect('command.filter_options', array($this, 'filterCommandOptions'));
}
/**
* Filters command options.
*
* @param sfEvent $event
* @param array $options
*
* @return array
*/
public function filterCommandOptions(sfEvent $event, $options) {
// force generator class when running build-filters task
if ('sfDoctrineBuildFiltersTask' === get_class($event->getSubject()))
{
$options = array('--generator-class=myFormFilterGenerator');
}
return $options;
}
}
<?php
/**
* @author johnwards
* @link http://stackoverflow.com/questions/2881379/symfony-forms-how-to-change-default-widget-for-form-generation
*/
class myFormFilterGenerator extends sfDoctrineFormFilterGenerator
{
public function getWidgetOptionsForColumn($column)
{
switch ($column->getDoctrineType())
{
case 'string';
return "array('with_empty'=> false)";
break;
default:
return parent::getWidgetOptionsForColumn($column);
}
}
}
@mikeplavo
Copy link

Hello,

I tried your code
put the dispatcher code in config/ProjectConfiguration.class.php
and myFormFilterGenerator .class.php in lib folder.
When I ran the task: doctrine:build-filters i have this message:
The execution of task "doctrine:build-filters" failed.

  • Not enough arguments.

symfony doctrine:build-filters [--application[="..."]] [--env="..."] [--model-dir-name="..."] [--filter-dir-name="..."] [--generator-class="..."]

What's going wrong?
Thks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment