@@ -215,16 +215,73 @@ protected function validateExtension($filename, $extensions) {
215215 * {@inheritdoc}
216216 */
217217 public function buildConfigurationForm (array $ form , FormStateInterface $ form_state ) {
218- $ configuration = $ this ->getConfiguration ();
219- $ settings = $ configuration ['settings ' ];
220- $ form += parent ::buildConfigurationForm ($ form , $ form_state );
218+ $ configuration = $ this ->configuration ;
219+
220+ $ form ['upload_location ' ] = [
221+ '#type ' => 'textfield ' ,
222+ '#title ' => $ this ->t ('Upload location ' ),
223+ '#default_value ' => $ configuration ['upload_location ' ],
224+ ];
221225
222226 $ form ['dropzone_description ' ] = [
223227 '#type ' => 'textfield ' ,
224228 '#title ' => $ this ->t ('Dropzone drag-n-drop zone text ' ),
225- '#default_value ' => $ settings ['dropzone_description ' ],
229+ '#default_value ' => $ configuration ['dropzone_description ' ],
230+ ];
231+
232+ preg_match ('%[\d\.]% ' , $ configuration ['max_filesize ' ], $ matches );
233+ $ max_filesize = !empty ($ matches ) ? array_shift ($ matches ) : '1 ' ;
234+
235+ $ form ['max_filesize ' ] = [
236+ '#type ' => 'number ' ,
237+ '#title ' => $ this ->t ('Maximum size of files ' ),
238+ '#min ' => '0 ' ,
239+ '#field_suffix ' => $ this ->t ('MB ' ),
240+ '#default_value ' => $ max_filesize ,
241+ ];
242+
243+ $ form ['extensions ' ] = [
244+ '#type ' => 'textfield ' ,
245+ '#title ' => $ this ->t ('Allowed file extensions ' ),
246+ '#desciption ' => $ this ->t ('A space separated list of file extensions ' ),
247+ '#default_value ' => $ configuration ['extensions ' ],
226248 ];
227249
228250 return $ form ;
229251 }
252+
253+ /**
254+ * {@inheritdoc}
255+ */
256+ public function validateConfigurationForm (array &$ form , FormStateInterface $ form_state ) {
257+ $ values = $ form_state ->getValues ()['table ' ][$ this ->uuid ()]['form ' ];
258+
259+ if (!empty ($ values ['extensions ' ])) {
260+ $ extensions = explode (' ' , $ values ['extensions ' ]);
261+ $ fail = FALSE ;
262+
263+ foreach ($ extensions as $ extension ) {
264+ if (preg_match ('%^\w*$% ' , $ extension ) !== 1 ) {
265+ $ fail = TRUE ;
266+ }
267+ }
268+
269+ if ($ fail ) {
270+ $ form_state ->setErrorByName ('extensions ' , $ this ->t ('Invalid extension list format. ' ));
271+ }
272+ }
273+ }
274+
275+ /**
276+ * {@inheritdoc}
277+ */
278+ public function submitConfigurationForm (array &$ form , FormStateInterface $ form_state ) {
279+ $ values = $ form_state ->getValues ()['table ' ][$ this ->uuid ()]['form ' ];
280+
281+ if (!empty ($ values ['max_filesize ' ])) {
282+ $ this ->configuration ['max_filesize ' ] = $ values ['max_filesize ' ] . 'M ' ;
283+ }
284+ }
285+
286+
230287}
0 commit comments