Forked from aledujke/sfWidgetFormSchemaFormatterBootstrap.class.php
Created
April 14, 2012 07:51
-
-
Save b1rdex/2382743 to your computer and use it in GitHub Desktop.
Symfony form formatter to use with Twitter Bootstrap v2.0 CSS
This file contains hidden or 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 sfWidgetFormSchemaFormatterBootstrap extends sfWidgetFormSchemaFormatter | |
{ | |
protected | |
$rowFormat = "<div class=\"control-group %row_class%\">\n %label%\n <div class=\"controls\">\n %field%\n %error%\n %help%\n %hidden_fields%\n </div>\n</div>\n", | |
$errorRowFormat = '%errors%', | |
$errorListFormatInARow = "<span class=\"help-inline\">%errors%</span>\n", | |
$errorRowFormatInARow = "%error% ", | |
$namedErrorRowFormatInARow = "%name%: %error% ", | |
$helpFormat = '<p class="help-block">%help%</p>', | |
$decoratorFormat = ''; | |
public function formatRow($label, $field, $errors = array(), $help = '', $hiddenFields = null) | |
{ | |
$row = parent::formatRow( | |
$label, | |
$field, | |
$errors, | |
$help, | |
$hiddenFields | |
); | |
return strtr($row, array( | |
'%row_class%' => count($errors) ? ' error' : '', | |
)); | |
} | |
public function generateLabel($name, $attributes = array()) | |
{ | |
if(isset($attributes['class'])) | |
{ | |
$attributes['class'] .= ' control-label'; | |
} | |
else | |
{ | |
$attributes['class'] = 'control-label'; | |
} | |
return parent::generateLabel($name, $attributes); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment