From 9847bda9f0e618d32072e6246ed219fee9229caa Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 10 Jun 2018 10:44:22 +0200 Subject: [PATCH] Add GUI support for abstract menu package installation plugin See #2545 --- ...actMenuPackageInstallationPlugin.class.php | 213 ++++++++++++++++++ wcfsetup/install/lang/en.xml | 13 ++ 2 files changed, 226 insertions(+) diff --git a/wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php index a6d3b25428..6514eda01a 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php @@ -1,10 +1,24 @@ getNodeById('data'); + + $dataContainer->appendChildren([ + TextFormField::create('menuItem') + ->objectProperty('name') + ->label('wcf.acp.pip.abstractMenu.menuItem'), + + SingleSelectionFormField::create('parentMenuItem') + ->objectProperty('parent') + ->label('wcf.acp.pip.abstractForm.parentMenuItem') + ->filterable(), + + ClassNameFormField::create('menuItemController') + ->objectProperty('controller') + ->label('wcf.acp.pip.abstractForm.menuItemController') + ->implementedInterface(IPage::class), + + TextFormField::create('menuItemLink') + ->objectProperty('link') + ->label('wcf.acp.pip.abstractMenu.menuItemLink') + ->description('wcf.acp.pip.abstractMenu.menuItemLink.description') + ->objectProperty('link') + ->addValidator(new FormFieldValidator('linkSpecified', function(TextFormField $formField) { + /** @var ClassNameFormField $menuItemController */ + $menuItemController = $formField->getDocument()->getNodeById('menuItemController'); + + // ensure that either a menu item controller is specified or a link + if ($formField->getSaveValue() === '' && $menuItemController->getSaveValue() === '') { + $formField->addValidationError( + new FormFieldValidationError( + 'noLinkSpecified', + 'wcf.acp.pip.abstractMenu.menuItemLink.error.noLinkSpecified' + ) + ); + } + })) + ->addValidator(new FormFieldValidator('format', function(TextFormField $formField) { + if ($formField->getSaveValue() !== '') { + /** @var ClassNameFormField $menuItemController */ + $menuItemController = $formField->getDocument()->getNodeById('menuItemController'); + + if (!$menuItemController->getSaveValue() && !Url::is($formField->getSaveValue())) { + $formField->addValidationError( + new FormFieldValidationError( + 'noLink', + 'wcf.acp.pip.abstractMenu.menuItemLink.error.noLink' + ) + ); + } + else if ($menuItemController->getSaveValue() && Url::is($formField->getSaveValue())) { + $formField->addValidationError( + new FormFieldValidationError( + 'isLink', + 'wcf.acp.pip.abstractMenu.menuItemLink.error.isLink' + ) + ); + } + } + })), + + OptionFormField::create() + ->description('wcf.acp.pip.abstractMenu.options.description') + ->saveValueType(OptionFormField::SAVE_VALUE_TYPE_CSV) + ->packageIDs(array_merge( + [$this->installation->getPackage()->packageID], + array_keys($this->installation->getPackage()->getAllRequiredPackages()) + )), + + UserGroupOptionFormField::create() + ->description('wcf.acp.pip.abstractMenu.options.description') + ->saveValueType(OptionFormField::SAVE_VALUE_TYPE_CSV) + ->packageIDs(array_merge( + [$this->installation->getPackage()->packageID], + array_keys($this->installation->getPackage()->getAllRequiredPackages()) + )), + + IntegerFormField::create('showOrder') + ->objectProperty('showorder') + ->label('wcf.acp.pip.abstractMenu.showOrder') + ->description('wcf.acp.pip.abstractMenu.showOrder.description') + ->objectProperty('showorder') + ->minimum(1) + ]); + } + + /** + * @inheritDoc + * @since 3.2 + */ + protected function getElementData(\DOMElement $element): array { + $data = [ + 'menuItem' => $element->getAttribute('name'), + 'packageID' => $this->installation->getPackage()->packageID + ]; + + $parentMenuItem = $element->getElementsByTagName('parent')->item(0); + if ($parentMenuItem !== null) { + $data['parentMenuItem'] = $parentMenuItem->nodeValue; + } + + $controller = $element->getElementsByTagName('controller')->item(0); + if ($controller !== null) { + $data['menuItemController'] = $controller->nodeValue; + } + + $link = $element->getElementsByTagName('link')->item(0); + if ($link !== null) { + $data['menuItemLink'] = $link->nodeValue; + } + + $options = $element->getElementsByTagName('options')->item(0); + if ($options !== null) { + $data['options'] = $options->nodeValue; + } + + $permissions = $element->getElementsByTagName('permissions')->item(0); + if ($permissions !== null) { + $data['permissions'] = $permissions->nodeValue; + } + + $showOrder = $element->getElementsByTagName('showOrder')->item(0); + if ($showOrder !== null) { + $data['showOrder'] = $showOrder->nodeValue; + } + + return $data; + } + + /** + * @inheritDoc + * @since 3.2 + */ + public function getElementIdentifier(\DOMElement $element): string { + return $element->getAttribute('name'); + } + + /** + * @inheritDoc + * @since 3.2 + */ + protected function setEntryListKeys(IDevtoolsPipEntryList $entryList) { + $entryList->setKeys([ + 'menuItem' => 'wcf.acp.pip.abstractMenu.menuItem', + 'parentMenuItem' => 'wcf.acp.pip.abstractMenu.parentMenuItem' + ]); + } + + /** + * @inheritDoc + * @since 3.2 + */ + protected function sortDocument(\DOMDocument $document) { + $this->sortImportDelete($document); + + $compareFunction = function(\DOMElement $element1, \DOMElement $element2) { + return strcmp( + $element1->getAttribute('name'), + $element2->getAttribute('name') + ); + }; + + $this->sortChildNodes($document->getElementsByTagName('import'), $compareFunction); + $this->sortChildNodes($document->getElementsByTagName('delete'), $compareFunction); + } + + /** + * @inheritDoc + * @since 3.2 + */ + protected function writeEntry(\DOMDocument $document, IFormDocument $form): \DOMElement { + $formData = $form->getData()['data']; + + $menuItem = $document->createElement($this->tagName); + $menuItem->setAttribute('name', $formData['name']); + + foreach (['parent', 'controller', 'link', 'options', 'permissions', 'showorder'] as $field) { + if (isset($formData[$field]) && $formData[$field] !== '') { + $menuItem->appendChild($document->createElement($field, (string) $formData[$field])); + } + } + + $document->getElementsByTagName('import')->item(0)->appendChild($menuItem); + + return $menuItem; + } } diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index b451cec215..f020e4aaa6 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1900,6 +1900,19 @@ When prompted for the notification URL for the instant payment notifications, pl + + + + + + + + + + + + + -- 2.20.1