FEATURE: allow users to enter extra classes on form fields via the cms. PATCH via TotalNet. Fixes: #5791

This commit is contained in:
Will Rossiter 2012-04-14 23:03:43 +12:00
parent 965d8d00b0
commit aa67b9da2f
2 changed files with 59 additions and 6 deletions

View File

@ -395,6 +395,13 @@ class UserDefinedForm_Controller extends Page_Controller {
}
}
// if this field has an extra class
if($editableField->getSetting('ExtraClass')) {
$field->addExtraClass(Convert::raw2att(
$editableField->getSetting('ExtraClass')
));
}
// set the values passed by the url to the field
$request = $this->getRequest();
$value = Convert::raw2att($request->getVar($field->name));

View File

@ -10,6 +10,13 @@ class EditableFormField extends DataObject {
static $default_sort = "Sort";
/**
* A list of CSS classes that can be added
*
* @var array
*/
public static $allowed_css = array();
static $db = array(
"Name" => "Varchar",
"Title" => "Varchar(255)",
@ -144,6 +151,19 @@ class EditableFormField extends DataObject {
$this->setSettings($settings);
}
/**
* Set the allowed css classes for the extraClass custom setting
*
* @param array The permissible CSS classes to add
*/
public function setAllowedCss(array $allowed) {
if (is_array($allowed_css)){
foreach ($allowed_css as $k => $v){
self::$allowed_css[$k] = (!is_null($v)) ? $v : $k;
}
}
}
/**
* Return just one custom setting or empty string if it does
* not exist
@ -342,12 +362,38 @@ class EditableFormField extends DataObject {
* @return FieldSet
*/
public function getFieldConfiguration() {
return new FieldSet(
new TextField(
$extraClass = ($this->getSetting('ExtraClass')) ? $this->getSetting('ExtraClass') : '';
if (is_array(self::$allowed_css) && !empty(self::$allowed_css)) {
foreach(self::$allowed_css as $k => $v) {
if (!is_array($v)) $cssList[$k]=$v;
elseif ($k == $this->ClassName()) $cssList = array_merge($cssList, $v);
}
$ec = new DropdownField(
$this->getSettingName('ExtraClass'),
_t('EditableFormField.EXTRACLASSA', 'Extra Styling/Layout'),
$cssList, $extraClass
);
}
else {
$ec = new TextField(
$this->getSettingName('ExtraClass'),
_t('EditableFormField.EXTRACLASSB', 'Extra css Class - separate multiples with a space'),
$extraClass
);
}
$right = new TextField(
$this->getSettingName('RightTitle'),
_t('EditableFormField.RIGHTTITLE', 'Right Title'),
$this->getSetting('RightTitle')
)
);
return new FieldSet(
$ec,
$right
);
}