Skip to content

Instantly share code, notes, and snippets.

@kriswallsmith
Created July 18, 2009 07:40
Show Gist options
  • Save kriswallsmith/149464 to your computer and use it in GitHub Desktop.
Save kriswallsmith/149464 to your computer and use it in GitHub Desktop.
<?php
class RequiredLabelsFormatterTable extends sfWidgetFormSchemaFormatterTable
{
protected
$requiredLabelClass = 'required';
public function generateLabel($name, $attributes = array())
{
// loop up to find the "required_fields" option
$widget = $this->widgetSchema;
do
{
$requiredFields = (array) $widget->getOption('required_fields');
}
while ($widget = $widget->getParent());
// add a class (non-destructively) if the field is required
if (in_array($this->widgetSchema->generateName($name), $requiredFields))
{
$attributes['class'] = isset($attributes['class']) ?
$attributes['class'].' '.$this->requiredLabelClass :
$this->requiredLabelClass;
}
return parent::generateLabel($name, $attributes);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment