From 16f48eeab8fcd4912a749c4a6470ffa947ebc7f9 Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Fri, 19 Jun 2020 17:12:29 +1200 Subject: [PATCH] Reorganise GraphQL and Extensions classes --- _config/config.yml | 8 +++--- _config/graphql.yml | 11 +++----- .../AjaxField.php} | 13 ++++++--- .../LeftAndMain.php} | 15 ++++------ .../ModalController.php} | 28 +++++++++++++++---- .../LinkDescriptionQuery.php} | 9 +++--- .../LinkDescriptionType.php} | 6 ++-- .../LinkTypeQuery.php} | 10 ++++--- .../LinkTypeType.php} | 7 ++--- 9 files changed, 62 insertions(+), 45 deletions(-) rename src/{TreeDropdownFieldExtension.php => Extensions/AjaxField.php} (55%) rename src/{LeftAndMainExtension.php => Extensions/LeftAndMain.php} (63%) rename src/{ModalControllerExtension.php => Extensions/ModalController.php} (73%) rename src/{Type/LinkDescriptionQueryCreator.php => GraphQL/LinkDescriptionQuery.php} (81%) rename src/{Type/LinkDescriptionTypeCreator.php => GraphQL/LinkDescriptionType.php} (81%) rename src/{Type/QueryCreator.php => GraphQL/LinkTypeQuery.php} (82%) rename src/{Type/TypeCreator.php => GraphQL/LinkTypeType.php} (86%) diff --git a/_config/config.yml b/_config/config.yml index 63b6eb8b..4de82235 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -4,16 +4,16 @@ Name: linkfield SilverStripe\Admin\LeftAndMain: extensions: - - SilverStripe\Link\LeftAndMainExtension + - SilverStripe\Link\Extensions\LeftAndMain SilverStripe\Admin\ModalController: extensions: - - SilverStripe\Link\ModalControllerExtension + - SilverStripe\Link\Extensions\ModalController SilverStripe\Forms\TreeDropdownField: extensions: - - SilverStripe\Link\TreeDropdownFieldExtension + - SilverStripe\Link\Extensions\AjaxField SilverStripe\CMS\Forms\AnchorSelectorField: extensions: - - SilverStripe\Link\TreeDropdownFieldExtension + - SilverStripe\Link\Extensions\AjaxField diff --git a/_config/graphql.yml b/_config/graphql.yml index 1c50aa41..ce700c62 100644 --- a/_config/graphql.yml +++ b/_config/graphql.yml @@ -5,12 +5,9 @@ SilverStripe\GraphQL\Manager: schemas: admin: types: - LinkType: 'SilverStripe\Link\Type\TypeCreator' - LinkDescription: 'SilverStripe\Link\Type\LinkDescriptionTypeCreator' + LinkType: SilverStripe\Link\GraphQL\LinkTypeType + LinkDescription: SilverStripe\Link\GraphQL\LinkDescriptionType queries: - readLinkTypes: 'SilverStripe\Link\Type\QueryCreator' - readLinkDescription: 'SilverStripe\Link\Type\LinkDescriptionQueryCreator' - -# mutations: -# createFile: 'SilverStripe\AssetAdmin\GraphQL\CreateFileMutationCreator' + readLinkTypes: SilverStripe\Link\GraphQL\LinkTypeQuery + readLinkDescription: SilverStripe\Link\GraphQL\LinkDescriptionQuery diff --git a/src/TreeDropdownFieldExtension.php b/src/Extensions/AjaxField.php similarity index 55% rename from src/TreeDropdownFieldExtension.php rename to src/Extensions/AjaxField.php index cad9b869..9c1ea7c5 100644 --- a/src/TreeDropdownFieldExtension.php +++ b/src/Extensions/AjaxField.php @@ -1,17 +1,22 @@ getOwner(); $formName = $owner->getForm()->getName(); diff --git a/src/LeftAndMainExtension.php b/src/Extensions/LeftAndMain.php similarity index 63% rename from src/LeftAndMainExtension.php rename to src/Extensions/LeftAndMain.php index 6cfde171..ce604b28 100644 --- a/src/LeftAndMainExtension.php +++ b/src/Extensions/LeftAndMain.php @@ -1,15 +1,18 @@ init(); } @@ -19,10 +22,4 @@ public function updateClientConfig(&$clientConfig) 'schemaUrl' => $this->getOwner()->Link('methodSchema/Modals/DynamicLink'), ]; } - - public function DynamicLink() - { - - } - } diff --git a/src/ModalControllerExtension.php b/src/Extensions/ModalController.php similarity index 73% rename from src/ModalControllerExtension.php rename to src/Extensions/ModalController.php index b6ddd90e..8e83e55e 100644 --- a/src/ModalControllerExtension.php +++ b/src/Extensions/ModalController.php @@ -1,16 +1,23 @@ 'editorAnchorLink', // Matches LeftAndMain::methodSchema args @@ -30,7 +37,7 @@ public function DynamicLink() // Show link text field if requested $linkDataJsonStr = $this->getOwner()->controller->getRequest()->getVar('data'); - /** @var ModalController $owner */ + /** @var OwnerController $owner */ $owner = $this->getOwner(); $factory = FormFactory::singleton(); @@ -44,7 +51,12 @@ public function DynamicLink() )->loadDataFrom($data); } - private function getContext() + /** + * Build the context to pass to the Form Link Factory + * @return array + * @throws HTTPResponse_Exception + */ + private function getContext(): array { $linkTypeKey = $this->getOwner()->controller->getRequest()->getVar('key'); if (empty($linkTypeKey)) { @@ -65,7 +77,11 @@ private function getContext() ]; } - private function getData() + /** + * Extract the Link Data out of the Request. + * @return array + */ + private function getData(): array { $data = []; $dataString = $this->getOwner()->controller->getRequest()->getVar('data'); diff --git a/src/Type/LinkDescriptionQueryCreator.php b/src/GraphQL/LinkDescriptionQuery.php similarity index 81% rename from src/Type/LinkDescriptionQueryCreator.php rename to src/GraphQL/LinkDescriptionQuery.php index cc401401..86ae1bf7 100644 --- a/src/Type/LinkDescriptionQueryCreator.php +++ b/src/GraphQL/LinkDescriptionQuery.php @@ -1,15 +1,16 @@