Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

mikeplavo commented Nov 25, 2010

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