From 7060e332945e3ff1497f34041d9e89161e650851 Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Tue, 7 Jan 2025 18:22:05 +0530 Subject: [PATCH] ACMS-4237: Remove Dependency of acquia_cms_common from Site Studio. --- .../acquia_cms_site_studio.info.yml | 1 - .../acquia_cms_site_studio.install | 20 +-- .../acquia_cms_site_studio.module | 2 +- .../config/install/user.role.developer.yml | 7 +- .../src/Facade/ConfigHandlerFacade.php | 123 ++++++++++++++++++ 5 files changed, 138 insertions(+), 15 deletions(-) create mode 100644 modules/acquia_cms_site_studio/src/Facade/ConfigHandlerFacade.php diff --git a/modules/acquia_cms_site_studio/acquia_cms_site_studio.info.yml b/modules/acquia_cms_site_studio/acquia_cms_site_studio.info.yml index 288224379..40756fac0 100644 --- a/modules/acquia_cms_site_studio/acquia_cms_site_studio.info.yml +++ b/modules/acquia_cms_site_studio/acquia_cms_site_studio.info.yml @@ -4,7 +4,6 @@ description: 'Module for Site Studio Installation Code.' core_version_requirement: ^9.5 || ^10 || ^11 type: module dependencies: - - acquia_cms_common:acquia_cms_common - cohesion_base_styles # phpcs:ignore - cohesion_custom_styles # phpcs:ignore - cohesion_elements # phpcs:ignore diff --git a/modules/acquia_cms_site_studio/acquia_cms_site_studio.install b/modules/acquia_cms_site_studio/acquia_cms_site_studio.install index 7b39ed171..5aa781684 100644 --- a/modules/acquia_cms_site_studio/acquia_cms_site_studio.install +++ b/modules/acquia_cms_site_studio/acquia_cms_site_studio.install @@ -5,7 +5,7 @@ * Contains install-time code for the Acquia CMS profile. */ -use Drupal\acquia_cms_common\Facade\ConfigHandlerFacade; +use Drupal\acquia_cms_site_studio\Facade\ConfigHandlerFacade; use Drupal\cohesion\Controller\AdministrationController; use Drupal\cohesion_sync\Event\SiteStudioSyncFilesEvent; use Drupal\cohesion_sync\EventSubscriber\Import\SiteStudioSyncFilesSubscriber; @@ -129,14 +129,18 @@ function acquia_cms_site_studio_install($is_syncing) { 'sitestudio_config_management', ]; $module_installer->install($modules_to_install); - } -} -/** - * Implements hook_module_preinstall(). - */ -function acquia_cms_site_studio_module_preinstall($module) { - \Drupal::service('acquia_cms_common.utility')->setModulePreinstallTriggered($module); + // Add text format permission to developer role. + $role = \Drupal::entityTypeManager()->getStorage('user_role')->load('developer'); + $editors = $entity_type_manager->getStorage('editor')->loadMultiple([ + 'cohesion', + 'filtered_html', + 'full_html', + ]); + foreach($editors as $editor) { + $role->grantPermission('use text format ' . $editor->id()); + } + } } /** diff --git a/modules/acquia_cms_site_studio/acquia_cms_site_studio.module b/modules/acquia_cms_site_studio/acquia_cms_site_studio.module index bfbbaa7a4..b0f460020 100644 --- a/modules/acquia_cms_site_studio/acquia_cms_site_studio.module +++ b/modules/acquia_cms_site_studio/acquia_cms_site_studio.module @@ -5,7 +5,7 @@ * File for the Site Studio Installation Code. */ -use Drupal\acquia_cms_common\Facade\ConfigHandlerFacade; +use Drupal\acquia_cms_site_studio\Facade\ConfigHandlerFacade; use Drupal\acquia_cms_site_studio\Facade\CohesionFacade; use Drupal\acquia_cms_site_studio\Form\AcquiaCmsSiteStudioSiteConfigureForm; use Drupal\acquia_cms_site_studio\Helper\SiteStudioPermissionHelper; diff --git a/modules/acquia_cms_site_studio/config/install/user.role.developer.yml b/modules/acquia_cms_site_studio/config/install/user.role.developer.yml index 31d031c25..f630e3799 100644 --- a/modules/acquia_cms_site_studio/config/install/user.role.developer.yml +++ b/modules/acquia_cms_site_studio/config/install/user.role.developer.yml @@ -4,12 +4,9 @@ dependencies: { } id: developer label: 'Low Code Site Builder' weight: -9 -is_admin: null +is_admin: false permissions: # The above comment is only applicable till here. - - 'use text format filtered_html' - - 'use text format full_html' - - 'view the administration theme' - 'access animate on view' - 'access component builder elements group' - 'access component content' @@ -28,7 +25,6 @@ permissions: - 'access media elements group' - 'access menu elements group' - 'access view elements group' - - 'use text format cohesion' - 'access analytics' - 'access cohesion sync' - 'access color_picker' @@ -53,3 +49,4 @@ permissions: - 'administer style helpers' - 'administer view templates' - 'administer website settings' + - 'view the administration theme' diff --git a/modules/acquia_cms_site_studio/src/Facade/ConfigHandlerFacade.php b/modules/acquia_cms_site_studio/src/Facade/ConfigHandlerFacade.php new file mode 100644 index 000000000..7e7028652 --- /dev/null +++ b/modules/acquia_cms_site_studio/src/Facade/ConfigHandlerFacade.php @@ -0,0 +1,123 @@ +configFactory = $config_factory; + $this->entityTypeManager = $entity_type_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('entity_type.manager') + ); + } + + /** + * Set module name. + * + * @param string $name + * Module name. + * + * @return void + * Setting the module name. + */ + public function setModuleName(string $name): void { + $this->moduleName = $name; + } + + /** + * Function to add default settings of node revision delete. + * + * @param array $settings + * Config settings data. + * + * @return void + * Saving the default settings. + */ + public function processConfigSettings(array $settings): void { + $config = $this->configFactory->getEditable("$this->moduleName.settings"); + foreach ($settings as $key => $value) { + $config->set($key, $value); + } + $config->save(); + } + + /** + * Set third party settings for entity. + * + * @param array $entity + * Entity data. + * @param array $settings + * Third party setting data. + * + * @return void + * Saving the third party settings. + */ + public function processThirdPartySettings(array $entity, array $settings): void { + if ($entity) { + // Get the entity storage with respective entity_type. + $type = $this->entityTypeManager->getStorage($entity['entity_type']); + $entityLoad = $type->load($entity['bundle']); + // @phpstan-ignore-next-line + $getThirdPartySettings = $entityLoad ? $entityLoad->get('third_party_settings') : NULL; + // Set the third party settings. + if (!empty($entityLoad) && !isset($getThirdPartySettings[$this->moduleName])) { + foreach ($settings as $key => $value) { + // @phpstan-ignore-next-line + $entityLoad->setThirdPartySetting($this->moduleName, $key, $value); + } + $entityLoad->save(); + } + } + } + +}