mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Merge pull request #31 from open-sausages/feature/add-segment-field-notemplates
Feature/add segment field notemplates
This commit is contained in:
commit
9c98f8d345
@ -484,7 +484,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
$watch[$fieldToWatch] = array();
|
$watch[$fieldToWatch] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$watch[$fieldToWatch][] = array(
|
$watch[$fieldToWatch][] = array(
|
||||||
'expression' => $expression,
|
'expression' => $expression,
|
||||||
'holder_selector' => $holderSelector,
|
'holder_selector' => $holderSelector,
|
||||||
'view' => $view,
|
'view' => $view,
|
||||||
|
@ -15,6 +15,7 @@ class EditableCheckboxGroupField extends EditableMultipleOptionField {
|
|||||||
|
|
||||||
public function getFormField() {
|
public function getFormField() {
|
||||||
$field = new UserFormsCheckboxSetField($this->Name, $this->EscapedTitle, $this->getOptionsMap());
|
$field = new UserFormsCheckboxSetField($this->Name, $this->EscapedTitle, $this->getOptionsMap());
|
||||||
|
$field->setTemplate('forms/UserFormsCheckboxSetField');
|
||||||
|
|
||||||
// Set the default checked items
|
// Set the default checked items
|
||||||
$defaultCheckedItems = $this->getDefaultOptions();
|
$defaultCheckedItems = $this->getDefaultOptions();
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\Forms\SegmentField;
|
||||||
|
use SilverStripe\Forms\SegmentFieldModifier\IDSegmentFieldModifier;
|
||||||
|
use SilverStripe\Forms\SegmentFieldModifier\SlugSegmentFieldModifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the base class of a editable form field
|
* Represents the base class of a editable form field
|
||||||
* object like {@link EditableTextField}.
|
* object like {@link EditableTextField}.
|
||||||
*
|
*
|
||||||
* @package userforms
|
* @package userforms
|
||||||
|
*
|
||||||
|
* @property string Name
|
||||||
|
*
|
||||||
* @method DataList DisplayRules() List of EditableCustomRule objects
|
* @method DataList DisplayRules() List of EditableCustomRule objects
|
||||||
*/
|
*/
|
||||||
class EditableFormField extends DataObject {
|
class EditableFormField extends DataObject {
|
||||||
@ -154,7 +162,11 @@ class EditableFormField extends DataObject {
|
|||||||
),
|
),
|
||||||
TextField::create('Title'),
|
TextField::create('Title'),
|
||||||
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(
|
||||||
|
UnderscoreSegmentFieldModifier::create()->setDefault('Field'),
|
||||||
|
DisambiguationSegmentFieldModifier::create(),
|
||||||
|
))->setPreview($this->Name)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -281,7 +293,7 @@ class EditableFormField extends DataObject {
|
|||||||
|
|
||||||
// Set a field name.
|
// Set a field name.
|
||||||
if(!$this->Name) {
|
if(!$this->Name) {
|
||||||
$this->Name = $this->RecordClassName . $this->ID;
|
$this->Name = get_class($this) . '_' . $this->ID;
|
||||||
$this->write();
|
$this->write();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
54
code/modifiers/DisambiguationSegmentFieldModifier.php
Normal file
54
code/modifiers/DisambiguationSegmentFieldModifier.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\Forms\SegmentFieldModifier\AbstractSegmentFieldModifier;
|
||||||
|
|
||||||
|
class DisambiguationSegmentFieldModifier extends AbstractSegmentFieldModifier {
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getPreview($value) {
|
||||||
|
if($this->form instanceof Form && $record = $this->form->getRecord()) {
|
||||||
|
$parent = $record->Parent();
|
||||||
|
|
||||||
|
$try = $value;
|
||||||
|
|
||||||
|
$sibling = EditableformField::get()
|
||||||
|
->filter('ParentID', $parent->ID)
|
||||||
|
->filter('Name', $try)
|
||||||
|
->where('"ID" != ' . $record->ID)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$counter = 1;
|
||||||
|
|
||||||
|
while($sibling !== null) {
|
||||||
|
$try = $value . '_' . $counter++;
|
||||||
|
|
||||||
|
$sibling = EditableformField::get()
|
||||||
|
->filter('ParentID', $parent->ID)
|
||||||
|
->filter('Name', $try)
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($try !== $value) {
|
||||||
|
return $try;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getSuggestion($value) {
|
||||||
|
return $this->getPreview($value);
|
||||||
|
}
|
||||||
|
}
|
27
code/modifiers/UnderscoreSegmentFieldModifier.php
Normal file
27
code/modifiers/UnderscoreSegmentFieldModifier.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\Forms\SegmentFieldModifier\SlugSegmentFieldModifier;
|
||||||
|
|
||||||
|
class UnderscoreSegmentFieldModifier extends SlugSegmentFieldModifier {
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getPreview($value) {
|
||||||
|
return str_replace('-', '_', parent::getPreview($value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getSuggestion($value) {
|
||||||
|
return str_replace('-', '_', parent::getSuggestion($value));
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,8 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"silverstripe/framework": ">=3.1.0",
|
"silverstripe/framework": ">=3.1.0",
|
||||||
"silverstripe/cms": ">=3.1.0",
|
"silverstripe/cms": ">=3.1.0",
|
||||||
"silverstripe-australia/gridfieldextensions": "1.1.0"
|
"silverstripe-australia/gridfieldextensions": "1.1.0",
|
||||||
|
"silverstripe/segment-field": "^1.0"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"colymba/gridfield-bulk-editing-tools": "Allows for bulk management of form submissions"
|
"colymba/gridfield-bulk-editing-tools": "Allows for bulk management of form submissions"
|
||||||
|
@ -18,7 +18,10 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
|||||||
|
|
||||||
// load the form
|
// load the form
|
||||||
$this->get($form->URLSegment);
|
$this->get($form->URLSegment);
|
||||||
$response = $this->submitForm('UserForm_Form', null, array('basic-text-name' => 'Basic Value'));
|
|
||||||
|
$field = $this->objFromFixture('EditableTextField', 'basic-text');
|
||||||
|
|
||||||
|
$response = $this->submitForm('UserForm_Form', null, array($field->Name => 'Basic Value'));
|
||||||
|
|
||||||
// should have a submitted form field now
|
// should have a submitted form field now
|
||||||
$submitted = DataObject::get('SubmittedFormField', "\"Name\" = 'basic-text-name'");
|
$submitted = DataObject::get('SubmittedFormField', "\"Name\" = 'basic-text-name'");
|
||||||
|
Loading…
Reference in New Issue
Block a user