mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
FEATURE: allow users to enter extra classes on form fields via the cms. PATCH via TotalNet. Fixes: #5791
This commit is contained in:
parent
965d8d00b0
commit
aa67b9da2f
@ -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
|
// set the values passed by the url to the field
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$value = Convert::raw2att($request->getVar($field->name));
|
$value = Convert::raw2att($request->getVar($field->name));
|
||||||
|
@ -10,6 +10,13 @@ class EditableFormField extends DataObject {
|
|||||||
|
|
||||||
static $default_sort = "Sort";
|
static $default_sort = "Sort";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of CSS classes that can be added
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $allowed_css = array();
|
||||||
|
|
||||||
static $db = array(
|
static $db = array(
|
||||||
"Name" => "Varchar",
|
"Name" => "Varchar",
|
||||||
"Title" => "Varchar(255)",
|
"Title" => "Varchar(255)",
|
||||||
@ -144,6 +151,19 @@ class EditableFormField extends DataObject {
|
|||||||
$this->setSettings($settings);
|
$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
|
* Return just one custom setting or empty string if it does
|
||||||
* not exist
|
* not exist
|
||||||
@ -342,12 +362,38 @@ class EditableFormField extends DataObject {
|
|||||||
* @return FieldSet
|
* @return FieldSet
|
||||||
*/
|
*/
|
||||||
public function getFieldConfiguration() {
|
public function getFieldConfiguration() {
|
||||||
|
$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(
|
return new FieldSet(
|
||||||
new TextField(
|
$ec,
|
||||||
$this->getSettingName('RightTitle'),
|
$right
|
||||||
_t('EditableFormField.RIGHTTITLE', 'Right Title'),
|
|
||||||
$this->getSetting('RightTitle')
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user