Skip to content

Instantly share code, notes, and snippets.

@pborreli
Created September 13, 2010 16:12
Show Gist options
  • Save pborreli/577526 to your computer and use it in GitHub Desktop.
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
<?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;
}
}
<?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