mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
BUG Fix issues when adding new formfields:
- Page no longer reloads on new field - Preview mode no longer errors on new field - Sort order of field dropdown is ordered - Default field type to Text field instead of abstract base class - Ensure fields named 'Field' is invalidated.
This commit is contained in:
parent
9c98f8d345
commit
9535a2acd7
@ -57,7 +57,7 @@ class UserFormFieldEditorExtension extends DataExtension {
|
|||||||
->addComponents(
|
->addComponents(
|
||||||
$editableColumns,
|
$editableColumns,
|
||||||
new GridFieldButtonRow(),
|
new GridFieldButtonRow(),
|
||||||
GridFieldAddClassesButton::create('EditableFormField')
|
GridFieldAddClassesButton::create('EditableTextField')
|
||||||
->setButtonName(_t('UserFormFieldEditorExtension.ADD_FIELD', 'Add Field'))
|
->setButtonName(_t('UserFormFieldEditorExtension.ADD_FIELD', 'Add Field'))
|
||||||
->setButtonClass('ss-ui-action-constructive'),
|
->setButtonClass('ss-ui-action-constructive'),
|
||||||
GridFieldAddClassesButton::create('EditableFormStep')
|
GridFieldAddClassesButton::create('EditableFormStep')
|
||||||
|
@ -3,11 +3,7 @@
|
|||||||
/**
|
/**
|
||||||
* A button which allows objects to be created with a specified classname(s)
|
* A button which allows objects to be created with a specified classname(s)
|
||||||
*/
|
*/
|
||||||
class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider, GridField_URLHandler {
|
class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider, GridField_ActionProvider {
|
||||||
|
|
||||||
private static $allowed_actions = array(
|
|
||||||
'handleAdd'
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of fragment to insert into
|
* Name of fragment to insert into
|
||||||
@ -127,7 +123,7 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
|||||||
*/
|
*/
|
||||||
public function getClassesCreate($grid) {
|
public function getClassesCreate($grid) {
|
||||||
// Get explicit or fallback class list
|
// Get explicit or fallback class list
|
||||||
$classes = $this->modelClasses;
|
$classes = $this->getClasses();
|
||||||
if(empty($classes) && $grid) {
|
if(empty($classes) && $grid) {
|
||||||
$classes = array($grid->getModelClass());
|
$classes = array($grid->getModelClass());
|
||||||
}
|
}
|
||||||
@ -165,45 +161,59 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
|||||||
$buttonName = _t('GridField.Add', 'Add {name}', array('name' => $objectName));
|
$buttonName = _t('GridField.Add', 'Add {name}', array('name' => $objectName));
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = new ArrayData(array(
|
$addAction = new GridField_FormAction(
|
||||||
'Title' => $this->getButtonName(),
|
$grid,
|
||||||
'ButtonClass' => $this->getButtonClass(),
|
$this->getAction(),
|
||||||
'Link' => Controller::join_links($grid->Link(), $this->getAction())
|
$buttonName,
|
||||||
));
|
$this->getAction(),
|
||||||
|
array()
|
||||||
|
);
|
||||||
|
$addAction->setAttribute('data-icon', 'add');
|
||||||
|
|
||||||
|
if($this->getButtonClass()) {
|
||||||
|
$addAction->addExtraClass($this->getButtonClass());
|
||||||
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
$this->getFragment() => $data->renderWith(__CLASS__)
|
$this->targetFragment => $addAction->forTemplate()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function getActions($gridField) {
|
||||||
|
return array(
|
||||||
|
$this->getAction()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the action suburl for this component
|
* Get the action suburl for this component
|
||||||
*
|
*
|
||||||
* @return type
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getAction() {
|
protected function getAction() {
|
||||||
$classes = implode('-', $this->getClasses());
|
return 'add-classes-' . strtolower(implode('-', $this->getClasses()));
|
||||||
return Controller::join_links('add-classes', $classes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
|
||||||
* {@inheritDoc}
|
switch(strtolower($actionName)) {
|
||||||
*/
|
case $this->getAction():
|
||||||
public function getURLHandlers($grid) {
|
return $this->handleAdd($gridField);
|
||||||
return array(
|
default:
|
||||||
$this->getAction() => 'handleAdd'
|
return null;
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles adding a new instance of a selected class.
|
* Handles adding a new instance of a selected class.
|
||||||
*
|
*
|
||||||
* @param GridField $grid
|
* @param GridField $grid
|
||||||
* @param SS_HTTPRequest $request
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function handleAdd($grid, $request) {
|
public function handleAdd($grid) {
|
||||||
$classes = $this->getClassesCreate($grid);
|
$classes = $this->getClassesCreate($grid);
|
||||||
|
|
||||||
if(empty($classes)) {
|
if(empty($classes)) {
|
||||||
throw new SS_HTTPResponse_Exception(400);
|
throw new SS_HTTPResponse_Exception(400);
|
||||||
}
|
}
|
||||||
@ -216,10 +226,7 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
|||||||
$list->add($item);
|
$list->add($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return directly to the gridfield again
|
// Should trigger a simple reload
|
||||||
return $grid
|
return null;
|
||||||
->getForm()
|
|
||||||
->getController()
|
|
||||||
->redirectBack();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -782,10 +782,10 @@ JS
|
|||||||
* Allows the use of field values in email body.
|
* Allows the use of field values in email body.
|
||||||
*
|
*
|
||||||
* @param ArrayList fields
|
* @param ArrayList fields
|
||||||
* @return ViewableData
|
* @return ArrayData
|
||||||
*/
|
*/
|
||||||
private function getMergeFieldsMap($fields = array()) {
|
private function getMergeFieldsMap($fields = array()) {
|
||||||
$data = new ViewableData();
|
$data = new ArrayData(array());
|
||||||
|
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$data->setField($field->Name, DBField::create_field('Text', $field->Value));
|
$data->setField($field->Name, DBField::create_field('Text', $field->Value));
|
||||||
|
@ -164,7 +164,7 @@ class EditableFormField extends DataObject {
|
|||||||
TextField::create('Default', _t('EditableFormField.DEFAULT', 'Default value')),
|
TextField::create('Default', _t('EditableFormField.DEFAULT', 'Default value')),
|
||||||
TextField::create('RightTitle', _t('EditableFormField.RIGHTTITLE', 'Right title')),
|
TextField::create('RightTitle', _t('EditableFormField.RIGHTTITLE', 'Right title')),
|
||||||
SegmentField::create('Name')->setModifiers(array(
|
SegmentField::create('Name')->setModifiers(array(
|
||||||
UnderscoreSegmentFieldModifier::create()->setDefault('Field'),
|
UnderscoreSegmentFieldModifier::create()->setDefault('FieldName'),
|
||||||
DisambiguationSegmentFieldModifier::create(),
|
DisambiguationSegmentFieldModifier::create(),
|
||||||
))->setPreview($this->Name)
|
))->setPreview($this->Name)
|
||||||
)
|
)
|
||||||
@ -277,6 +277,10 @@ class EditableFormField extends DataObject {
|
|||||||
public function onBeforeWrite() {
|
public function onBeforeWrite() {
|
||||||
parent::onBeforeWrite();
|
parent::onBeforeWrite();
|
||||||
|
|
||||||
|
if($this->Name === 'Field') {
|
||||||
|
throw new ValidationException('Field name cannot be "Field"');
|
||||||
|
}
|
||||||
|
|
||||||
if(!$this->Sort && $this->ParentID) {
|
if(!$this->Sort && $this->ParentID) {
|
||||||
$parentID = $this->ParentID;
|
$parentID = $this->ParentID;
|
||||||
$this->Sort = EditableFormField::get()
|
$this->Sort = EditableFormField::get()
|
||||||
@ -772,6 +776,7 @@ class EditableFormField extends DataObject {
|
|||||||
$editableFieldClasses[$class] = $singleton->i18n_singular_name();
|
$editableFieldClasses[$class] = $singleton->i18n_singular_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
asort($editableFieldClasses);
|
||||||
return $editableFieldClasses;
|
return $editableFieldClasses;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Styles for cms
|
* Styles for cms
|
||||||
*/
|
*/
|
||||||
.cms .uf-field-editor > div.ss-gridfield-buttonrow-before {
|
|
||||||
margin-bottom: 10px;
|
|
||||||
overflow: auto;
|
|
||||||
}
|
|
||||||
.cms .uf-field-editor table.ss-gridfield-table .ss-gridfield-item, .cms .uf-field-editor table.ss-gridfield-table .ss-gridfield-item:hover {
|
.cms .uf-field-editor table.ss-gridfield-table .ss-gridfield-item, .cms .uf-field-editor table.ss-gridfield-table .ss-gridfield-item:hover {
|
||||||
background: white;
|
background: white;
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,6 @@
|
|||||||
|
|
||||||
.uf-field-editor {
|
.uf-field-editor {
|
||||||
|
|
||||||
> div.ss-gridfield-buttonrow-before {
|
|
||||||
margin-bottom: 10px;
|
|
||||||
overflow: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Row styles
|
// Row styles
|
||||||
table.ss-gridfield-table {
|
table.ss-gridfield-table {
|
||||||
|
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
<a href="$Link.ATT" class="action action-detail ss-ui-button ui-button ui-widget ui-state-default ui-corner-all new new-link $ButtonClass.ATT" data-icon="add">
|
|
||||||
$Title.XML
|
|
||||||
</a>
|
|
Loading…
Reference in New Issue
Block a user