-
-
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
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 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') ? ' *' : null; | |
$widgetSchema[$fieldName]->setLabel($label . $asterisk . ' :'); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment