Skip to content

Instantly share code, notes, and snippets.

@cbou
Forked from pborreli/Configuration.class.php
Created May 16, 2011 14:16
Show Gist options
  • Save cbou/974511 to your computer and use it in GitHub Desktop.
Save cbou/974511 to your computer and use it in GitHub Desktop.
adding ":" to all labels and "*" to all required fields inside symfony 1.3+ forms
<?php
class privateConfiguration extends sfApplicationConfiguration
{
public function configure()
{
$this->dispatcher->connect('form.post_configure', array($this, 'listenToFormPostConfigure'));
}
/**
* Listens to the view.configure_format event.
*
* @param sfEvent An sfEvent instance
* @static
*/
static function listenToFormPostConfigure(sfEvent $event)
{
$form = $event->getSubject();
$widgetSchema = $form->getWidgetSchema();
foreach ($form->getValidatorSchema()->getFields() as $fieldName => $validator)
{
if (isset($widgetSchema[$fieldName]))
{
$label = $widgetSchema[$fieldName]->getLabel() ? $widgetSchema[$fieldName]->getLabel() : sfInflector::humanize($fieldName);
$asterisk = $validator->getOption('required') ? '&nbsp;*' : null;
$widgetSchema[$fieldName]->setLabel($label . $asterisk . '&nbsp;:');
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment