@@ -16,6 +16,24 @@ abstract class Form implements ArrayAccess, Iterator, Countable
1616 const PREFIX_FORMAT = '%s-%s ' ;
1717 const NON_FIELD_ERRORS = '__all__ ' ;
1818
19+ /**
20+ * Array with form data.
21+ * @var array
22+ */
23+ private $ data = null ;
24+
25+ /**
26+ * Array with form data files.
27+ * @var array
28+ */
29+ private $ files = null ;
30+
31+ /**
32+ * Array with initial data.
33+ * @var array
34+ */
35+ private $ initial = array ();
36+
1937 /**
2038 * List of form errors.
2139 * @var array
@@ -66,14 +84,15 @@ abstract class Form implements ArrayAccess, Iterator, Countable
6684
6785 /**
6886 * Constructor method
87+ *
6988 * @param array $args Arguments
7089 */
7190 public function __construct (array $ args = array ())
7291 {
73- $ this ->data = array_key_exists ('data ' , $ args ) ? $ args ['data ' ] : null ;
74- $ this ->files = array_key_exists ('files ' , $ args ) ? $ args ['files ' ] : null ;
92+ $ this ->data = array_key_exists ('data ' , $ args ) ? $ args ['data ' ] : $ this -> data ;
93+ $ this ->files = array_key_exists ('files ' , $ args ) ? $ args ['files ' ] : $ this -> files ;
7594 $ this ->prefix = array_key_exists ('prefix ' , $ args ) ? $ args ['prefix ' ] : $ this ->prefix ;
76- $ this ->initial = array_key_exists ('initial ' , $ args ) ? $ args ['initial ' ] : array () ;
95+ $ this ->initial = array_key_exists ('initial ' , $ args ) ? $ args ['initial ' ] : $ this -> initial ;
7796 $ this ->css_classes = array_key_exists ('css_classes ' , $ args ) ? $ args ['css_classes ' ] : $ this ->css_classes ;
7897
7998 $ this ->is_bound = !is_null ($ this ->data ) or !is_null ($ this ->files );
@@ -82,6 +101,7 @@ public function __construct(array $args = array())
82101
83102 /**
84103 * Method to be redefined with form fields
104+ *
85105 * @return array Desired fields for this form.
86106 */
87107 protected static function setFields ()
@@ -91,15 +111,37 @@ protected static function setFields()
91111
92112 /**
93113 * Return if form is bounded or not.
114+ *
94115 * @return boolean
95116 */
96117 public function isBound ()
97118 {
98119 return $ this ->is_bound ;
99120 }
100121
122+ /**
123+ * Return form data array.
124+ *
125+ * @return array
126+ */
127+ public function getData ()
128+ {
129+ return $ this ->data ;
130+ }
131+
132+ /**
133+ * Return form files data array.
134+ *
135+ * @return array
136+ */
137+ public function getFiles ()
138+ {
139+ return $ this ->files ;
140+ }
141+
101142 /**
102143 * Return css classes to be added to each widget.
144+ *
103145 * @return array
104146 */
105147 public function getCssClasses ()
@@ -109,6 +151,7 @@ public function getCssClasses()
109151
110152 /**
111153 * Return error css class to be added on case of field error.
154+ *
112155 * @return array
113156 */
114157 public function getErrorCssClass ()
@@ -118,7 +161,9 @@ public function getErrorCssClass()
118161
119162 /**
120163 * Special method to make errors accessible as a attribute.
164+ *
121165 * @param string $name Attribute name.
166+ *
122167 * @return mixed
123168 */
124169 public function __get (string $ name )
@@ -134,7 +179,9 @@ public function __get(string $name)
134179
135180 /**
136181 * Add a prefix to a name.
182+ *
137183 * @param string $field_name Field name.
184+ *
138185 * @return string
139186 */
140187 public function addPrefix (string $ field_name )
@@ -148,6 +195,7 @@ public function addPrefix(string $field_name)
148195
149196 /**
150197 * Add error to specific $field_name, if null, define to NON_FIELD_ERRORS.
198+ *
151199 * @param mixed $error
152200 * @param string $field_name
153201 */
@@ -222,6 +270,7 @@ private function cleanForm()
222270
223271 /**
224272 * Redefine if need to validate crossfields.
273+ *
225274 * @return array Cleaned data
226275 */
227276 protected function clean ()
@@ -231,6 +280,7 @@ protected function clean()
231280
232281 /**
233282 * Return cleaned data values.
283+ *
234284 * @return array Cleaned data
235285 */
236286 public function getCleanedData ()
@@ -240,7 +290,9 @@ public function getCleanedData()
240290
241291 /**
242292 * Return cleaned field value.
293+ *
243294 * @param string $field_name Name of field.
295+ *
244296 * @return string Cleaned field value.
245297 */
246298 public function getCleanedField (string $ field_name )
@@ -250,7 +302,9 @@ public function getCleanedField(string $field_name)
250302
251303 /**
252304 * Check if field has error on it.
305+ *
253306 * @param string $field_name Name of field to check
307+ *
254308 * @return boolean
255309 */
256310 public function hasErrors ($ field_name )
@@ -260,7 +314,9 @@ public function hasErrors($field_name)
260314
261315 /**
262316 * Return all errors associated to $field_name.
317+ *
263318 * @param string $field_name Field name
319+ *
264320 * @return ErrorList
265321 */
266322 public function getFieldErrors (string $ field_name )
@@ -274,6 +330,7 @@ public function getFieldErrors(string $field_name)
274330
275331 /**
276332 * Return errors not associated with any field.
333+ *
277334 * @return ErrorList
278335 */
279336 public function getNonFieldErrors ()
@@ -287,6 +344,7 @@ public function getNonFieldErrors()
287344
288345 /**
289346 * Check if form is valid.
347+ *
290348 * @return bool
291349 */
292350 public function isValid ()
@@ -296,6 +354,7 @@ public function isValid()
296354
297355 /**
298356 * Check if form is valid.
357+ *
299358 * @return bool
300359 */
301360 public function getInitialForField ($ field , $ field_name )
@@ -327,6 +386,7 @@ public function offsetUnset($offset)
327386
328387 /**
329388 * @throws UnexpectedValueException
389+ *
330390 * @return BoundField
331391 */
332392 public function offsetGet ($ offset )
0 commit comments