-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAdvancedWidgetEditorInterface.php
78 lines (63 loc) · 2.95 KB
/
AdvancedWidgetEditorInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
class AdvancedWidgetEditorInterface extends DataExtension {
private $_widgetEditor=null;
/**
* Sets the widget editor instance for the owner
* @param {AdvancedWidgetAreaEditor} $editor Editor to be used
*/
public function setWidgetEditor(AdvancedWidgetAreaEditor $editor) {
$this->_widgetEditor=$editor;
}
/**
* Wrapper for generating the display of the widget
* @return {string} HTML to be used as the display
*/
public function AdvancedEditableSegment() {
return $this->owner->renderWith('AdvancedWidgetEditor');
}
/**
* @return string
*/
public function AdvancedName() {
return 'Widget['.$this->_widgetEditor->getName().']['.$this->owner->ID.']';
}
/**
* Gets the fields to be used in the form
* @return {FieldList} Fields to be used in the form
*/
public function AdvancedCMSEditor() {
$fields=$this->owner->getCMSFields();
$outputFields=new FieldList();
foreach($fields as $field) {
$field->setForm(new AdvancedWidgetFormShiv($this->_widgetEditor, $this->owner));
$name=$field->getName();
if(isset($this->owner->$name) || $this->owner->hasMethod($name) || ($this->owner->hasMethod('hasField') && $this->owner->hasField($name))) {
$field->setValue($this->owner->__get($name), $this->owner);
}
//Workaround for UploadField fixes an issue detecting if the relationship is a has_one relationship
if($field instanceof UploadField && $this->owner->has_one($name)) {
$field->setAllowedMaxFileNumber(1);
}
//Workaround for silverstripe/silverstripe-widgets#25
if($field instanceof CheckboxField) {
if($this->_widgetEditor->getForm() && $this->_widgetEditor->getForm()->getController() && $data=$this->_widgetEditor->getForm()->getController()->getRequest()->requestVar('Widget')) {
if(isset($data[$this->_widgetEditor->getName()][$this->owner->ID])) {
$data=$data[$this->_widgetEditor->getName()][$this->owner->ID];
if(!isset($data[$field->getName()])) {
$field->setValue(0);
}
}
}
}
$name=preg_replace("/([A-Za-z0-9\-_]+)/", "Widget[".$this->_widgetEditor->getName()."][".$this->owner->ID."][\\1]", $name);
$field->setName($name);
//Fix the gridstate field
if($field instanceof GridField) {
$field->getState(false)->setName($name.'[GridState]');
}
$outputFields->push($field);
}
return $outputFields;
}
}
?>