From 6c74dc897a327199f3bebf31dee8178a64d9ed32 Mon Sep 17 00:00:00 2001 From: Matthias Schuhmayer <38959016+mattamon@users.noreply.github.com> Date: Thu, 23 May 2024 12:04:17 +0200 Subject: [PATCH] [Feature][WIP] Settings (#64) * Add system settings controller * Add settings provider concept * Apply php-cs-fixer changes * Consistency check --------- Co-authored-by: mattamon --- config/settings.yaml | 25 +++++++ .../CompilerPass/SettingsProviderPass.php | 46 +++++++++++++ .../PimcoreStudioBackendExtension.php | 1 + src/OpenApi/Config/Tags.php | 5 ++ src/PimcoreStudioBackendBundle.php | 2 + src/Setting/Controller/GetController.php | 66 +++++++++++++++++++ .../Provider/ConfigSettingsProvider.php | 45 +++++++++++++ .../Provider/SettingsProviderInterface.php | 25 +++++++ .../Provider/SystemSettingsProvider.php | 50 ++++++++++++++ .../Service/Loader/TaggedIteratorAdapter.php | 39 +++++++++++ .../SettingProviderLoaderInterface.php | 25 +++++++ src/Setting/Service/SettingsService.php | 41 ++++++++++++ .../Service/SettingsServiceInterface.php | 25 +++++++ 13 files changed, 395 insertions(+) create mode 100644 config/settings.yaml create mode 100644 src/DependencyInjection/CompilerPass/SettingsProviderPass.php create mode 100644 src/Setting/Controller/GetController.php create mode 100644 src/Setting/Provider/ConfigSettingsProvider.php create mode 100644 src/Setting/Provider/SettingsProviderInterface.php create mode 100644 src/Setting/Provider/SystemSettingsProvider.php create mode 100644 src/Setting/Service/Loader/TaggedIteratorAdapter.php create mode 100644 src/Setting/Service/SettingProviderLoaderInterface.php create mode 100644 src/Setting/Service/SettingsService.php create mode 100644 src/Setting/Service/SettingsServiceInterface.php diff --git a/config/settings.yaml b/config/settings.yaml new file mode 100644 index 000000000..8c9bb36aa --- /dev/null +++ b/config/settings.yaml @@ -0,0 +1,25 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + # controllers are imported separately to make sure they're public + # and have a tag that allows actions to type-hint services + Pimcore\Bundle\StudioBackendBundle\Setting\Controller\: + resource: '../src/Setting/Controller' + public: true + tags: [ 'controller.service_arguments' ] + + + Pimcore\Bundle\StudioBackendBundle\Setting\Service\SettingProviderLoaderInterface: + class: Pimcore\Bundle\StudioBackendBundle\Setting\Service\Loader\TaggedIteratorAdapter + + Pimcore\Bundle\StudioBackendBundle\Setting\Service\SettingsServiceInterface: + class: Pimcore\Bundle\StudioBackendBundle\Setting\Service\SettingsService + + Pimcore\Bundle\StudioBackendBundle\Setting\Provider\ConfigSettingsProvider: + tags: [ 'pimcore.studio_backend.settings_provider' ] + + Pimcore\Bundle\StudioBackendBundle\Setting\Provider\SystemSettingsProvider: + tags: [ 'pimcore.studio_backend.settings_provider' ] \ No newline at end of file diff --git a/src/DependencyInjection/CompilerPass/SettingsProviderPass.php b/src/DependencyInjection/CompilerPass/SettingsProviderPass.php new file mode 100644 index 000000000..805c34572 --- /dev/null +++ b/src/DependencyInjection/CompilerPass/SettingsProviderPass.php @@ -0,0 +1,46 @@ +findTaggedServiceIds(TaggedIteratorAdapter::SETTINGS_PROVIDER_TAG), + ); + + foreach ($taggedServices as $environmentType) { + $this->checkInterface($environmentType, SettingsProviderInterface::class); + } + } +} diff --git a/src/DependencyInjection/PimcoreStudioBackendExtension.php b/src/DependencyInjection/PimcoreStudioBackendExtension.php index 57d0652b2..e1c6144d2 100644 --- a/src/DependencyInjection/PimcoreStudioBackendExtension.php +++ b/src/DependencyInjection/PimcoreStudioBackendExtension.php @@ -64,6 +64,7 @@ public function load(array $configs, ContainerBuilder $container): void $loader->load('properties.yaml'); $loader->load('security.yaml'); $loader->load('services.yaml'); + $loader->load('settings.yaml'); $loader->load('translation.yaml'); $loader->load('versions.yaml'); diff --git a/src/OpenApi/Config/Tags.php b/src/OpenApi/Config/Tags.php index 3c4babb42..00366a4e6 100644 --- a/src/OpenApi/Config/Tags.php +++ b/src/OpenApi/Config/Tags.php @@ -57,6 +57,10 @@ name: Tags::Translation->name, description: 'Get translations either for a single key or multiple keys' )] +#[Tag( + name: Tags::Settings->name, + description: 'Get Settings' +)] #[Tag( name: Tags::Versions->name, description: 'Versions operations to get/list/publish/delete and cleanup versions' @@ -72,6 +76,7 @@ enum Tags: string case NotesForElement = 'Notes for Element'; case Properties = 'Properties'; case PropertiesForElement = 'Properties for Element'; + case Settings = 'Settings'; case Translation = 'Translation'; case Versions = 'Versions'; } diff --git a/src/PimcoreStudioBackendBundle.php b/src/PimcoreStudioBackendBundle.php index ebdb5435a..c27464c83 100644 --- a/src/PimcoreStudioBackendBundle.php +++ b/src/PimcoreStudioBackendBundle.php @@ -19,6 +19,7 @@ use Pimcore\Bundle\GenericDataIndexBundle\PimcoreGenericDataIndexBundle; use Pimcore\Bundle\StaticResolverBundle\PimcoreStaticResolverBundle; use Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass\FilterPass; +use Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass\SettingsProviderPass; use Pimcore\Extension\Bundle\AbstractPimcoreBundle; use Pimcore\Extension\Bundle\Installer\InstallerInterface; use Pimcore\HttpKernel\Bundle\DependentBundleInterface; @@ -63,6 +64,7 @@ public function getInstaller(): ?InstallerInterface public function build(ContainerBuilder $container): void { $container->addCompilerPass(new FilterPass()); + $container->addCompilerPass(new SettingsProviderPass()); } public static function registerDependentBundles(BundleCollection $collection): void diff --git a/src/Setting/Controller/GetController.php b/src/Setting/Controller/GetController.php new file mode 100644 index 000000000..0a5d215e7 --- /dev/null +++ b/src/Setting/Controller/GetController.php @@ -0,0 +1,66 @@ +name] + )] + #[SuccessResponse( + description: 'System settings', + content: new JsonContent(type: 'object', additionalProperties: true) + )] + #[MethodNotAllowedResponse] + #[UnsupportedMediaTypeResponse] + #[UnprocessableContentResponse] + public function getSystemSettings(): JsonResponse + { + return $this->jsonResponse($this->settingsService->getSettings()); + } +} diff --git a/src/Setting/Provider/ConfigSettingsProvider.php b/src/Setting/Provider/ConfigSettingsProvider.php new file mode 100644 index 000000000..5f9e21444 --- /dev/null +++ b/src/Setting/Provider/ConfigSettingsProvider.php @@ -0,0 +1,45 @@ + $this->config['assets']['tree_paging_limit'], + 'document_tree_paging_limit' => $this->config['documents']['tree_paging_limit'], + 'object_tree_paging_limit' => $this->config['objects']['tree_paging_limit'], + 'timezone' => $this->config['general']['timezone'], + ]; + + } +} diff --git a/src/Setting/Provider/SettingsProviderInterface.php b/src/Setting/Provider/SettingsProviderInterface.php new file mode 100644 index 000000000..2f2824bda --- /dev/null +++ b/src/Setting/Provider/SettingsProviderInterface.php @@ -0,0 +1,25 @@ +systemSettings = $systemSettingsConfig->getSystemSettingsConfig(); + } + + public function getSettings(): array + { + $requiredLanguages = + $this->systemSettings['general']['required_languages'] ?? + $this->systemSettings['general']['valid_languages']; + + + return [ + 'requiredLanguages' => $requiredLanguages, + 'debug_admin_translations' => (bool)$this->systemSettings['general']['debug_admin_translations'], + 'main_domain' => $this->systemSettings['general']['domain'], + ]; + } +} diff --git a/src/Setting/Service/Loader/TaggedIteratorAdapter.php b/src/Setting/Service/Loader/TaggedIteratorAdapter.php new file mode 100644 index 000000000..0955f9292 --- /dev/null +++ b/src/Setting/Service/Loader/TaggedIteratorAdapter.php @@ -0,0 +1,39 @@ +taggedSettingProviders]; + } +} diff --git a/src/Setting/Service/SettingProviderLoaderInterface.php b/src/Setting/Service/SettingProviderLoaderInterface.php new file mode 100644 index 000000000..368b0fa98 --- /dev/null +++ b/src/Setting/Service/SettingProviderLoaderInterface.php @@ -0,0 +1,25 @@ +settingProviderLoader->loadSettingProviders() as $settingProvider) { + $settings = [ + ... $settings, + ... $settingProvider->getSettings() + ]; + } + return $settings; + } +} diff --git a/src/Setting/Service/SettingsServiceInterface.php b/src/Setting/Service/SettingsServiceInterface.php new file mode 100644 index 000000000..434a6f3a9 --- /dev/null +++ b/src/Setting/Service/SettingsServiceInterface.php @@ -0,0 +1,25 @@ +