From 6f5733ca7aedd41ba3ed42641c2d6ec757268c87 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 23 Jul 2020 10:46:36 +0200 Subject: [PATCH] DRY up StyleAddForm::rebuildUploadFields() --- .../files/lib/acp/form/StyleAddForm.class.php | 69 ++++++------------- 1 file changed, 20 insertions(+), 49 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php b/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php index 3794989171..9c1c23de0d 100644 --- a/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php @@ -235,57 +235,28 @@ class StyleAddForm extends AbstractForm { } protected function rebuildUploadFields() { - $handler = UploadHandler::getInstance(); - - if ($handler->isRegisteredFieldId('image')) { - $handler->unregisterUploadField('image'); - } - $field = new UploadField('image'); - $field->setImageOnly(true); - $field->maxFiles = 1; - $handler->registerUploadField($field); - - if ($handler->isRegisteredFieldId('image2x')) { - $handler->unregisterUploadField('image2x'); - } - $field = new UploadField('image2x'); - $field->setImageOnly(true); - $field->maxFiles = 1; - $handler->registerUploadField($field); - - if ($handler->isRegisteredFieldId('pageLogo')) { - $handler->unregisterUploadField('pageLogo'); - } - $field = new UploadField('pageLogo'); - $field->setImageOnly(true); - $field->setAllowSvgImage(true); - $field->maxFiles = 1; - $handler->registerUploadField($field); - - if ($handler->isRegisteredFieldId('pageLogoMobile')) { - $handler->unregisterUploadField('pageLogoMobile'); - } - $field = new UploadField('pageLogoMobile'); - $field->setImageOnly(true); - $field->setAllowSvgImage(true); - $field->maxFiles = 1; - $handler->registerUploadField($field); - - if ($handler->isRegisteredFieldId('coverPhoto')) { - $handler->unregisterUploadField('coverPhoto'); - } - $field = new UploadField('coverPhoto'); - $field->setImageOnly(true); - $field->maxFiles = 1; - $handler->registerUploadField($field); + $fields = [ + 'image' => [ ], + 'image2x' => [ ], + 'pageLogo' => [ 'allowSvgImage' => true ], + 'pageLogoMobile' => [ 'allowSvgImage' => true ], + 'coverPhoto' => [ ], + 'favicon' => [ ], + ]; - if ($handler->isRegisteredFieldId('favicon')) { - $handler->unregisterUploadField('favicon'); + $handler = UploadHandler::getInstance(); + foreach ($fields as $name => $options) { + if ($handler->isRegisteredFieldId($name)) { + $handler->unregisterUploadField($name); + } + $field = new UploadField($name); + $field->setImageOnly(true); + if (isset($options['allowSvgImage'])) { + $field->setAllowSvgImage($options['allowSvgImage']); + } + $field->maxFiles = 1; + $handler->registerUploadField($field); } - $field = new UploadField('favicon'); - $field->setImageOnly(true); - $field->maxFiles = 1; - $handler->registerUploadField($field); } /** -- 2.20.1