Created
July 18, 2009 07:40
-
-
Save kriswallsmith/149464 to your computer and use it in GitHub Desktop.
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 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