@@ -45,10 +45,46 @@ public function __construct(DataObject $data, $title, $options = array()) {
45
45
// Set up fieldnames
46
46
$ this ->setupOptions ($ options );
47
47
48
+ $ this ->setupChildren ();
49
+
50
+ parent ::__construct ($ this ->getName (), $ title );
51
+ }
52
+
53
+ // Auto generate a name
54
+ public function getName () {
48
55
$ fieldNames = $ this ->getOption ('field_names ' );
56
+ return sprintf (
57
+ '%s_%s_%s ' ,
58
+ $ this ->data ->class ,
59
+ $ fieldNames ['Latitude ' ],
60
+ $ fieldNames ['Longitude ' ]
61
+ );
62
+ }
63
+
64
+ /**
65
+ * Merge options preserving the first level of array keys
66
+ * @param array $options
67
+ */
68
+ public function setupOptions (array $ options ) {
69
+ $ this ->options = static ::config ()->default_options ;
70
+ foreach ($ this ->options as $ name => &$ value ) {
71
+ if (isset ($ options [$ name ])) {
72
+ if (is_array ($ value )) {
73
+ $ value = array_merge ($ value , $ options [$ name ]);
74
+ }
75
+ else {
76
+ $ value = $ options [$ name ];
77
+ }
78
+ }
79
+ }
80
+ }
49
81
50
- // Auto generate a name
51
- $ name = sprintf ('%s_%s_%s ' , $ data ->class , $ fieldNames ['Latitude ' ], $ fieldNames ['Longitude ' ]);
82
+ /**
83
+ * Set up child hidden fields, and optionally the search box.
84
+ * @return FieldList the children
85
+ */
86
+ public function setupChildren () {
87
+ $ name = $ this ->getName ();
52
88
53
89
// Create the latitude/longitude hidden fields
54
90
$ this ->latField = HiddenField::create (
@@ -83,25 +119,7 @@ public function __construct(DataObject $data, $title, $options = array()) {
83
119
);
84
120
}
85
121
86
- parent ::__construct ($ name , $ title );
87
- }
88
-
89
- /**
90
- * Merge options preserving the first level of array keys
91
- * @param array $options
92
- */
93
- public function setupOptions (array $ options ) {
94
- $ this ->options = static ::config ()->default_options ;
95
- foreach ($ this ->options as $ name => &$ value ) {
96
- if (isset ($ options [$ name ])) {
97
- if (is_array ($ value )) {
98
- $ value = array_merge ($ value , $ options [$ name ]);
99
- }
100
- else {
101
- $ value = $ options [$ name ];
102
- }
103
- }
104
- }
122
+ return $ this ->children ;
105
123
}
106
124
107
125
/**
0 commit comments