mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge branch '3.5' into 3
This commit is contained in:
commit
19dd8d6824
@ -14,7 +14,7 @@ can be rendered out using custom templates using `setTemplate`.
|
|||||||
$field = new TextField(..);
|
$field = new TextField(..);
|
||||||
$field->setTemplate('MyCustomTextField');
|
$field->setTemplate('MyCustomTextField');
|
||||||
|
|
||||||
Both `MyCustomTemplate.ss` and `MyCustomTextField.ss` should be located in **mysite/templates/Includes/**
|
Both `MyCustomTemplate.ss` and `MyCustomTextField.ss` should be located in **mysite/templates/forms/** or the same directory as the core.
|
||||||
|
|
||||||
<div class="notice" markdown="1">
|
<div class="notice" markdown="1">
|
||||||
It's recommended to copy the contents of the template you're going to replace and use that as a start. For instance, if
|
It's recommended to copy the contents of the template you're going to replace and use that as a start. For instance, if
|
||||||
|
@ -1404,6 +1404,7 @@ class Form extends RequestHandler {
|
|||||||
if(is_object($data)) $this->record = $data;
|
if(is_object($data)) $this->record = $data;
|
||||||
|
|
||||||
// dont include fields without data
|
// dont include fields without data
|
||||||
|
/** @var FormField[] $dataFields */
|
||||||
$dataFields = $this->Fields()->dataFields();
|
$dataFields = $this->Fields()->dataFields();
|
||||||
if($dataFields) foreach($dataFields as $field) {
|
if($dataFields) foreach($dataFields as $field) {
|
||||||
$name = $field->getName();
|
$name = $field->getName();
|
||||||
@ -1436,15 +1437,31 @@ class Form extends RequestHandler {
|
|||||||
$val = $data[$name];
|
$val = $data[$name];
|
||||||
}
|
}
|
||||||
// If field is in array-notation we need to access nested data
|
// If field is in array-notation we need to access nested data
|
||||||
else if(strpos($name,'[')) {
|
else if(preg_match_all('/(.*)\[(.*)\]/U', $name, $matches)) {
|
||||||
// First encode data using PHP's method of converting nested arrays to form data
|
//discard first match which is just the whole string
|
||||||
$flatData = urldecode(http_build_query($data));
|
array_shift($matches);
|
||||||
// Then pull the value out from that flattened string
|
|
||||||
preg_match('/' . addcslashes($name,'[]') . '=([^&]*)/', $flatData, $matches);
|
|
||||||
|
|
||||||
if (isset($matches[1])) {
|
$keys = array_pop($matches);
|
||||||
|
$name = array_shift($matches);
|
||||||
|
$name = array_shift($name);
|
||||||
|
|
||||||
|
if (array_key_exists($name, $data)) {
|
||||||
|
$tmpData = &$data[$name];
|
||||||
|
// drill down into the data array looking for the corresponding value
|
||||||
|
foreach ($keys as $arrayKey) {
|
||||||
|
if ($arrayKey !== '') {
|
||||||
|
$tmpData = &$tmpData[$arrayKey];
|
||||||
|
} else {
|
||||||
|
//empty square brackets means new array
|
||||||
|
if (is_array($tmpData)) {
|
||||||
|
$tmpData = array_shift($tmpData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($tmpData) {
|
||||||
|
$val = $tmpData;
|
||||||
$exists = true;
|
$exists = true;
|
||||||
$val = $matches[1];
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,10 +58,10 @@ class FormTest extends FunctionalTest {
|
|||||||
$form->loadDataFrom($requestData);
|
$form->loadDataFrom($requestData);
|
||||||
|
|
||||||
$fields = $form->Fields();
|
$fields = $form->Fields();
|
||||||
$this->assertEquals($fields->fieldByName('key1')->Value(), 'val1');
|
$this->assertEquals('val1', $fields->fieldByName('key1')->Value());
|
||||||
$this->assertEquals($fields->fieldByName('namespace[key2]')->Value(), 'val2');
|
$this->assertEquals('val2', $fields->fieldByName('namespace[key2]')->Value());
|
||||||
$this->assertEquals($fields->fieldByName('namespace[key3][key4]')->Value(), 'val4');
|
$this->assertEquals('val4', $fields->fieldByName('namespace[key3][key4]')->Value());
|
||||||
$this->assertEquals($fields->fieldByName('othernamespace[key5][key6][key7]')->Value(), 'val7');
|
$this->assertEquals('val7', $fields->fieldByName('othernamespace[key5][key6][key7]')->Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubmitReadonlyFields() {
|
public function testSubmitReadonlyFields() {
|
||||||
|
@ -15,6 +15,20 @@ class HtmlEditorFieldTest extends FunctionalTest {
|
|||||||
|
|
||||||
protected $extraDataObjects = array('HtmlEditorFieldTest_Object');
|
protected $extraDataObjects = array('HtmlEditorFieldTest_Object');
|
||||||
|
|
||||||
|
public function testCasting() {
|
||||||
|
// Test special characters
|
||||||
|
$inputText = "These are some unicodes: ä, ö, & ü";
|
||||||
|
$field = new HTMLEditorField("Test", "Test");
|
||||||
|
$field->setValue($inputText);
|
||||||
|
$this->assertContains('These are some unicodes: ä, ö, & ü', $field->Field());
|
||||||
|
|
||||||
|
// Test shortcodes
|
||||||
|
$inputText = "Shortcode: [file_link id=4]";
|
||||||
|
$field = new HTMLEditorField("Test", "Test");
|
||||||
|
$field->setValue($inputText);
|
||||||
|
$this->assertContains('Shortcode: [file_link id=4]', $field->Field());
|
||||||
|
}
|
||||||
|
|
||||||
public function testBasicSaving() {
|
public function testBasicSaving() {
|
||||||
$obj = new HtmlEditorFieldTest_Object();
|
$obj = new HtmlEditorFieldTest_Object();
|
||||||
$editor = new HtmlEditorField('Content');
|
$editor = new HtmlEditorField('Content');
|
||||||
|
@ -2,6 +2,20 @@
|
|||||||
|
|
||||||
class TextareaFieldTest extends SapphireTest {
|
class TextareaFieldTest extends SapphireTest {
|
||||||
|
|
||||||
|
public function testCasting() {
|
||||||
|
// Test special characters
|
||||||
|
$inputText = "These are some unicodes: ä, ö, & ü";
|
||||||
|
$field = new TextareaField("Test", "Test");
|
||||||
|
$field->setValue($inputText);
|
||||||
|
$this->assertContains('These are some unicodes: ä, ö, & ü', $field->Field());
|
||||||
|
|
||||||
|
// Test shortcodes
|
||||||
|
$inputText = "Shortcode: [file_link id=4]";
|
||||||
|
$field = new TextareaField("Test", "Test");
|
||||||
|
$field->setValue($inputText);
|
||||||
|
$this->assertContains('Shortcode: [file_link id=4]', $field->Field());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quick smoke test to ensure that text with unicodes is being displayed properly in readonly fields.
|
* Quick smoke test to ensure that text with unicodes is being displayed properly in readonly fields.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user