Created
September 14, 2010 18:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
symfony doctrine:build-filters [--application[="..."]] [--env="..."] [--model-dir-name="..."] [--filter-dir-name="..."] [--generator-class="..."]
What's going wrong?
Thks