Created
September 13, 2010 16:12
-
-
Save pborreli/577526 to your computer and use it in GitHub Desktop.
how to replace a specific widget by another for all generated forms in symfony
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-forms task | |
if ('sfDoctrineBuildFormsTask' === get_class($event->getSubject())) | |
{ | |
$options = array('--generator-class=myFormGenerator'); | |
} | |
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 myFormGenerator extends sfDoctrineFormGenerator | |
{ | |
public function getWidgetClassForColumn($column) | |
{ | |
switch ($column->getDoctrineType()) | |
{ | |
case 'date': | |
return 'sfWidgetFormDateJQueryUI'; | |
break; | |
default: | |
return parent::getWidgetClassForColumn($column); | |
} | |
} | |
public function getWidgetOptionsForColumn($column) | |
{ | |
switch ($column->getDoctrineType()) | |
{ | |
case 'date': | |
return "array('image'=>'/images/icones/calendrier.gif')"; | |
break; | |
default: | |
return parent::getWidgetOptionsForColumn($column); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment