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(
|
||||
$editableColumns,
|
||||
new GridFieldButtonRow(),
|
||||
GridFieldAddClassesButton::create('EditableFormField')
|
||||
GridFieldAddClassesButton::create('EditableTextField')
|
||||
->setButtonName(_t('UserFormFieldEditorExtension.ADD_FIELD', 'Add Field'))
|
||||
->setButtonClass('ss-ui-action-constructive'),
|
||||
GridFieldAddClassesButton::create('EditableFormStep')
|
||||
|
@ -3,15 +3,11 @@
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $targetFragment;
|
||||
@ -127,7 +123,7 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
*/
|
||||
public function getClassesCreate($grid) {
|
||||
// Get explicit or fallback class list
|
||||
$classes = $this->modelClasses;
|
||||
$classes = $this->getClasses();
|
||||
if(empty($classes) && $grid) {
|
||||
$classes = array($grid->getModelClass());
|
||||
}
|
||||
@ -149,7 +145,7 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
}
|
||||
$this->modelClasses = $classes;
|
||||
}
|
||||
|
||||
|
||||
public function getHTMLFragments($grid) {
|
||||
// Check create permission
|
||||
$singleton = singleton($grid->getModelClass());
|
||||
@ -165,45 +161,59 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
$buttonName = _t('GridField.Add', 'Add {name}', array('name' => $objectName));
|
||||
}
|
||||
|
||||
$data = new ArrayData(array(
|
||||
'Title' => $this->getButtonName(),
|
||||
'ButtonClass' => $this->getButtonClass(),
|
||||
'Link' => Controller::join_links($grid->Link(), $this->getAction())
|
||||
));
|
||||
$addAction = new GridField_FormAction(
|
||||
$grid,
|
||||
$this->getAction(),
|
||||
$buttonName,
|
||||
$this->getAction(),
|
||||
array()
|
||||
);
|
||||
$addAction->setAttribute('data-icon', 'add');
|
||||
|
||||
if($this->getButtonClass()) {
|
||||
$addAction->addExtraClass($this->getButtonClass());
|
||||
}
|
||||
|
||||
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
|
||||
*
|
||||
* @return type
|
||||
* @return string
|
||||
*/
|
||||
protected function getAction() {
|
||||
$classes = implode('-', $this->getClasses());
|
||||
return Controller::join_links('add-classes', $classes);
|
||||
return 'add-classes-' . strtolower(implode('-', $this->getClasses()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getURLHandlers($grid) {
|
||||
return array(
|
||||
$this->getAction() => 'handleAdd'
|
||||
);
|
||||
public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
|
||||
switch(strtolower($actionName)) {
|
||||
case $this->getAction():
|
||||
return $this->handleAdd($gridField);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles adding a new instance of a selected class.
|
||||
*
|
||||
* @param GridField $grid
|
||||
* @param SS_HTTPRequest $request
|
||||
* @return null
|
||||
*/
|
||||
public function handleAdd($grid, $request) {
|
||||
public function handleAdd($grid) {
|
||||
$classes = $this->getClassesCreate($grid);
|
||||
|
||||
if(empty($classes)) {
|
||||
throw new SS_HTTPResponse_Exception(400);
|
||||
}
|
||||
@ -216,10 +226,7 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
$list->add($item);
|
||||
}
|
||||
|
||||
// Return directly to the gridfield again
|
||||
return $grid
|
||||
->getForm()
|
||||
->getController()
|
||||
->redirectBack();
|
||||
// Should trigger a simple reload
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -782,10 +782,10 @@ JS
|
||||
* Allows the use of field values in email body.
|
||||
*
|
||||
* @param ArrayList fields
|
||||
* @return ViewableData
|
||||
* @return ArrayData
|
||||
*/
|
||||
private function getMergeFieldsMap($fields = array()) {
|
||||
$data = new ViewableData();
|
||||
$data = new ArrayData(array());
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$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('RightTitle', _t('EditableFormField.RIGHTTITLE', 'Right title')),
|
||||
SegmentField::create('Name')->setModifiers(array(
|
||||
UnderscoreSegmentFieldModifier::create()->setDefault('Field'),
|
||||
UnderscoreSegmentFieldModifier::create()->setDefault('FieldName'),
|
||||
DisambiguationSegmentFieldModifier::create(),
|
||||
))->setPreview($this->Name)
|
||||
)
|
||||
@ -277,6 +277,10 @@ class EditableFormField extends DataObject {
|
||||
public function onBeforeWrite() {
|
||||
parent::onBeforeWrite();
|
||||
|
||||
if($this->Name === 'Field') {
|
||||
throw new ValidationException('Field name cannot be "Field"');
|
||||
}
|
||||
|
||||
if(!$this->Sort && $this->ParentID) {
|
||||
$parentID = $this->ParentID;
|
||||
$this->Sort = EditableFormField::get()
|
||||
@ -772,6 +776,7 @@ class EditableFormField extends DataObject {
|
||||
$editableFieldClasses[$class] = $singleton->i18n_singular_name();
|
||||
}
|
||||
|
||||
asort($editableFieldClasses);
|
||||
return $editableFieldClasses;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* 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 {
|
||||
background: white;
|
||||
}
|
||||
|
@ -6,11 +6,6 @@
|
||||
|
||||
.uf-field-editor {
|
||||
|
||||
> div.ss-gridfield-buttonrow-before {
|
||||
margin-bottom: 10px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
// Row styles
|
||||
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