From 0c2add3a655fa422fdfe09992bff8743347a2beb Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Fri, 20 Dec 2024 14:39:45 +0530 Subject: [PATCH 01/14] ACMS-4373: Make Acquia CMS Toolbar and Tour work independent. --- composer.lock | 12 +++++------ .../acquia_cms_toolbar.install | 21 +++++++++++++++++++ .../acquia_cms_toolbar.module | 10 ++++----- modules/acquia_cms_toolbar/composer.json | 2 +- .../acquia_cms_tour/acquia_cms_tour.info.yml | 2 -- .../acquia_cms_tour/acquia_cms_tour.install | 12 +++++++++++ .../acquia_cms_tour/acquia_cms_tour.module | 10 ++++----- modules/acquia_cms_tour/composer.json | 4 ++-- .../css/acquia_cms_tour_dashboard.css | 2 +- .../src/Controller/DashboardController.php | 4 ++-- .../src/Form/InstallationWizardForm.php | 2 +- .../Form/StarterKitSelectionWizardForm.php | 2 +- .../StarterKitConfigForm.php | 2 +- .../StarterKitSelectionForm.php | 2 +- .../AcquiaCmsTour/GoogleMapsApiForm.php | 2 +- .../AcquiaCmsTour/GoogleTagManagerForm.php | 6 +++--- .../Plugin/AcquiaCmsTour/RecaptchaForm.php | 2 +- .../src/Services/StarterKitService.php | 6 +++--- .../src/Functional/AcquiaGoogleMapsTest.php | 4 ++-- 19 files changed, 69 insertions(+), 38 deletions(-) diff --git a/composer.lock b/composer.lock index 11c249435..e6f6e1c1b 100644 --- a/composer.lock +++ b/composer.lock @@ -2390,7 +2390,7 @@ "dist": { "type": "path", "url": "./modules/acquia_cms_common", - "reference": "b2fe6b5717ef5c06a9a978b712bb12252d309a4f" + "reference": "36ebfe06447b4f28301a18995d197336fb6ce1f3" }, "require": { "acquia/drupal-environment-detector": "^1.5", @@ -2921,10 +2921,10 @@ "dist": { "type": "path", "url": "./modules/acquia_cms_toolbar", - "reference": "0cc6f26997c253705d6d7087a8878f7e690a29a0" + "reference": "be6fe88d08fdf50135d62a79fc3217b69bc6aa6b" }, "require": { - "drupal/acquia_cms_common": "^1.9 || ^2.1 || ^3.1", + "acquia/drupal-environment-detector": "^1.5", "drupal/admin_toolbar": "^3.3" }, "conflict": { @@ -2950,14 +2950,14 @@ "dist": { "type": "path", "url": "./modules/acquia_cms_tour", - "reference": "04e968e9b96a2b1fb974296aee91951ec849f6b9" + "reference": "63b34fbe25350ae4caed0d0232b3de2dff6f400f" }, "require": { - "drupal/acquia_cms_common": "^1.9 || ^2.1 || ^3.1", "drupal/checklistapi": "^2.1" }, "require-dev": { - "drupal/acquia_cms_place": "^1", + "drupal/geocoder": "^3.35 || ^4.10", + "drupal/google_tag": "^2", "drupal/recaptcha": "^3" }, "type": "drupal-module", diff --git a/modules/acquia_cms_toolbar/acquia_cms_toolbar.install b/modules/acquia_cms_toolbar/acquia_cms_toolbar.install index e00481b75..2490ee368 100644 --- a/modules/acquia_cms_toolbar/acquia_cms_toolbar.install +++ b/modules/acquia_cms_toolbar/acquia_cms_toolbar.install @@ -7,6 +7,27 @@ use Drupal\user\Entity\Role; +/** + * Implements hook_install(). + */ +function acquia_cms_toolbar_install($is_syncing) { + if (!$is_syncing) { + $roles = Role::loadMultiple(); + foreach ($roles as $role) { + switch ($role->id()) { + case 'content_administrator': + case 'content_author': + case 'content_editor': + case 'developer': + case 'site_builder': + case 'user_administrator': + user_role_grant_permissions($role->id(), ['access toolbar']); + break; + } + } + } +} + /** * Update role permission handler. */ diff --git a/modules/acquia_cms_toolbar/acquia_cms_toolbar.module b/modules/acquia_cms_toolbar/acquia_cms_toolbar.module index 391ce70da..c57335f43 100644 --- a/modules/acquia_cms_toolbar/acquia_cms_toolbar.module +++ b/modules/acquia_cms_toolbar/acquia_cms_toolbar.module @@ -6,8 +6,8 @@ */ use Acquia\DrupalEnvironmentDetector\AcquiaDrupalEnvironmentDetector as Environment; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Url; -use Drupal\user\RoleInterface; /** * Implements hook_preprocess_HOOK(). @@ -102,17 +102,17 @@ function _acquia_cms_toolbar_get_environment_indicator_color_config(): array { } /** - * Implements hook_content_model_role_presave_alter(). + * Implements hook_entity_insert(). */ -function acquia_cms_toolbar_content_model_role_presave_alter(RoleInterface &$role) { - switch ($role->id()) { +function acquia_cms_toolbar_entity_insert(EntityInterface $entity) { + switch ($entity->id()) { case 'content_administrator': case 'content_author': case 'content_editor': case 'developer': case 'site_builder': case 'user_administrator': - $role->grantPermission('access toolbar'); + user_role_grant_permissions($entity->id(), ['access toolbar']); break; } } diff --git a/modules/acquia_cms_toolbar/composer.json b/modules/acquia_cms_toolbar/composer.json index 9540e671d..8def6acf6 100644 --- a/modules/acquia_cms_toolbar/composer.json +++ b/modules/acquia_cms_toolbar/composer.json @@ -4,7 +4,7 @@ "license": "GPL-2.0-or-later", "type": "drupal-module", "require": { - "drupal/acquia_cms_common": "^1.9 || ^2.1 || ^3.1", + "acquia/drupal-environment-detector": "^1.5", "drupal/admin_toolbar": "^3.3" }, "conflict": { diff --git a/modules/acquia_cms_tour/acquia_cms_tour.info.yml b/modules/acquia_cms_tour/acquia_cms_tour.info.yml index e7e199b20..90af15d5d 100644 --- a/modules/acquia_cms_tour/acquia_cms_tour.info.yml +++ b/modules/acquia_cms_tour/acquia_cms_tour.info.yml @@ -3,5 +3,3 @@ package: "Acquia CMS" description: "Provides a tour page for Acquia CMS." type: module core_version_requirement: ^9.4 || ^10 || ^11 -dependencies: - - acquia_cms_common:acquia_cms_common diff --git a/modules/acquia_cms_tour/acquia_cms_tour.install b/modules/acquia_cms_tour/acquia_cms_tour.install index 875a9b526..c9c35aa76 100644 --- a/modules/acquia_cms_tour/acquia_cms_tour.install +++ b/modules/acquia_cms_tour/acquia_cms_tour.install @@ -7,6 +7,18 @@ use Drupal\user\Entity\Role; +/** + * Implements hook_install(). + */ +function acquia_cms_tour_install($is_syncing) { + if (!$is_syncing) { + $role = Role::load('content_administrator'); + if ($role) { + user_role_grant_permissions('content_administrator', ['access acquia cms tour dashboard']); + } + } +} + /** * Add state key for existing sites with Acquia CMS profile. */ diff --git a/modules/acquia_cms_tour/acquia_cms_tour.module b/modules/acquia_cms_tour/acquia_cms_tour.module index 3cd399189..fd0b8b611 100644 --- a/modules/acquia_cms_tour/acquia_cms_tour.module +++ b/modules/acquia_cms_tour/acquia_cms_tour.module @@ -5,7 +5,7 @@ * Contains hook implementations for the acquia_cms_tour module. */ -use Drupal\user\RoleInterface; +use Drupal\Core\Entity\EntityInterface; /** * Implements hook_menu_links_discovered_alter(). @@ -57,12 +57,12 @@ function acquia_cms_tour_modules_uninstalled(array $modules) { } /** - * Implements hook_content_model_role_presave_alter(). + * Implements hook_cms_tour_entity_insert(). */ -function acquia_cms_tour_content_model_role_presave_alter(RoleInterface &$role) { - switch ($role->id()) { +function acquia_cms_tour_entity_insert(EntityInterface $entity) { + switch ($entity->id()) { case 'content_administrator': - $role->grantPermission('access acquia cms tour dashboard'); + user_role_grant_permissions('content_administrator', ['access acquia cms tour dashboard']); break; } } diff --git a/modules/acquia_cms_tour/composer.json b/modules/acquia_cms_tour/composer.json index ca400c78d..44c209835 100644 --- a/modules/acquia_cms_tour/composer.json +++ b/modules/acquia_cms_tour/composer.json @@ -4,11 +4,11 @@ "license": "GPL-2.0-or-later", "type": "drupal-module", "require": { - "drupal/acquia_cms_common": "^1.9 || ^2.1 || ^3.1", "drupal/checklistapi": "^2.1" }, "require-dev": { - "drupal/acquia_cms_place": "^1", + "drupal/geocoder": "^3.35 || ^4.10", + "drupal/google_tag": "^2", "drupal/recaptcha": "^3" }, "config": { diff --git a/modules/acquia_cms_tour/css/acquia_cms_tour_dashboard.css b/modules/acquia_cms_tour/css/acquia_cms_tour_dashboard.css index 3b4a75b22..f00ed69ef 100644 --- a/modules/acquia_cms_tour/css/acquia_cms_tour_dashboard.css +++ b/modules/acquia_cms_tour/css/acquia_cms_tour_dashboard.css @@ -78,7 +78,7 @@ padding: 0; margin: 0; } -.acms-dashboard-form-wrapper .js-form-wrapper .js-form-wrapper .fieldset__wrapper{ +.acms-dashboard-form-wrapper .js-form-wrapper .js-form-wrapper .fieldset__wrapper { margin-left: 0; } .section-top { diff --git a/modules/acquia_cms_tour/src/Controller/DashboardController.php b/modules/acquia_cms_tour/src/Controller/DashboardController.php index cb68b3e61..3c378b9ce 100644 --- a/modules/acquia_cms_tour/src/Controller/DashboardController.php +++ b/modules/acquia_cms_tour/src/Controller/DashboardController.php @@ -2,13 +2,13 @@ namespace Drupal\acquia_cms_tour\Controller; -use Drupal\acquia_cms_tour\AcquiaCmsTourManager; -use Drupal\acquia_cms_tour\Services\StarterKitService; use Drupal\Component\Serialization\Json; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\DependencyInjection\ClassResolverInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\Url; +use Drupal\acquia_cms_tour\AcquiaCmsTourManager; +use Drupal\acquia_cms_tour\Services\StarterKitService; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; diff --git a/modules/acquia_cms_tour/src/Form/InstallationWizardForm.php b/modules/acquia_cms_tour/src/Form/InstallationWizardForm.php index 97047157f..270e259f0 100644 --- a/modules/acquia_cms_tour/src/Form/InstallationWizardForm.php +++ b/modules/acquia_cms_tour/src/Form/InstallationWizardForm.php @@ -2,13 +2,13 @@ namespace Drupal\acquia_cms_tour\Form; -use Drupal\acquia_cms_tour\AcquiaCmsTourManager; use Drupal\Core\DependencyInjection\ClassResolverInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; use Drupal\Core\Render\Renderer; use Drupal\Core\State\StateInterface; +use Drupal\acquia_cms_tour\AcquiaCmsTourManager; use Symfony\Component\DependencyInjection\ContainerInterface; /** diff --git a/modules/acquia_cms_tour/src/Form/StarterKitSelectionWizardForm.php b/modules/acquia_cms_tour/src/Form/StarterKitSelectionWizardForm.php index f2dfe1ac3..68000d21f 100644 --- a/modules/acquia_cms_tour/src/Form/StarterKitSelectionWizardForm.php +++ b/modules/acquia_cms_tour/src/Form/StarterKitSelectionWizardForm.php @@ -2,13 +2,13 @@ namespace Drupal\acquia_cms_tour\Form; -use Drupal\acquia_cms_tour\AcquiaCmsStarterKitManager; use Drupal\Core\DependencyInjection\ClassResolverInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; use Drupal\Core\Render\Renderer; use Drupal\Core\State\StateInterface; +use Drupal\acquia_cms_tour\AcquiaCmsStarterKitManager; use Symfony\Component\DependencyInjection\ContainerInterface; /** diff --git a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsStarterKit/StarterKitConfigForm.php b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsStarterKit/StarterKitConfigForm.php index e8b784098..fac24c484 100644 --- a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsStarterKit/StarterKitConfigForm.php +++ b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsStarterKit/StarterKitConfigForm.php @@ -2,9 +2,9 @@ namespace Drupal\acquia_cms_tour\Plugin\AcquiaCmsStarterKit; -use Drupal\acquia_cms_tour\Form\AcquiaCmsStarterKitBase; use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Form\FormStateInterface; +use Drupal\acquia_cms_tour\Form\AcquiaCmsStarterKitBase; use Symfony\Component\DependencyInjection\ContainerInterface; /** diff --git a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsStarterKit/StarterKitSelectionForm.php b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsStarterKit/StarterKitSelectionForm.php index bac080e73..cd5cba434 100644 --- a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsStarterKit/StarterKitSelectionForm.php +++ b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsStarterKit/StarterKitSelectionForm.php @@ -2,9 +2,9 @@ namespace Drupal\acquia_cms_tour\Plugin\AcquiaCmsStarterKit; -use Drupal\acquia_cms_tour\Form\AcquiaCmsStarterKitBase; use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Form\FormStateInterface; +use Drupal\acquia_cms_tour\Form\AcquiaCmsStarterKitBase; use Symfony\Component\DependencyInjection\ContainerInterface; /** diff --git a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleMapsApiForm.php b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleMapsApiForm.php index 64425e91a..10eabf23d 100644 --- a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleMapsApiForm.php +++ b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleMapsApiForm.php @@ -2,9 +2,9 @@ namespace Drupal\acquia_cms_tour\Plugin\AcquiaCmsTour; -use Drupal\acquia_cms_tour\Form\AcquiaCmsDashboardBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; +use Drupal\acquia_cms_tour\Form\AcquiaCmsDashboardBase; use Drupal\geocoder\GeocoderProviderInterface; use Symfony\Component\DependencyInjection\ContainerInterface; diff --git a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleTagManagerForm.php b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleTagManagerForm.php index e713f4f0d..15b71fe87 100644 --- a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleTagManagerForm.php +++ b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleTagManagerForm.php @@ -2,10 +2,10 @@ namespace Drupal\acquia_cms_tour\Plugin\AcquiaCmsTour; -use Drupal\acquia_cms_tour\Form\AcquiaCmsDashboardBase; use Drupal\Component\Utility\Html; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; +use Drupal\acquia_cms_tour\Form\AcquiaCmsDashboardBase; use Drupal\google_tag\Entity\TagContainer; /** @@ -92,7 +92,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { if ($accounts === []) { $config_name = 'google_tag.container.' . $account_default_value; $entity_accounts = $this->config($config_name)->get('tag_container_ids'); - if ($entity_accounts){ + if ($entity_accounts) { foreach ($entity_accounts as $index => $account) { $accounts[$index]['value'] = $account; $accounts[$index]['weight'] = $index; @@ -242,7 +242,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $config->set('tag_container_ids', array_values($tag_container_ids)); $config->save(); } - if($this->configFactory->getEditable('google_tag.settings')->get('default_google_tag_entity') !== NULL) { + if ($this->configFactory->getEditable('google_tag.settings')->get('default_google_tag_entity') !== NULL) { $this->configFactory->getEditable('google_tag.settings')->set('default_google_tag_entity', $config_id)->save(); } diff --git a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/RecaptchaForm.php b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/RecaptchaForm.php index 9ec748527..136774231 100644 --- a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/RecaptchaForm.php +++ b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/RecaptchaForm.php @@ -2,9 +2,9 @@ namespace Drupal\acquia_cms_tour\Plugin\AcquiaCmsTour; -use Drupal\acquia_cms_tour\Form\AcquiaCmsDashboardBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; +use Drupal\acquia_cms_tour\Form\AcquiaCmsDashboardBase; /** * Plugin implementation of the acquia_cms_tour. diff --git a/modules/acquia_cms_tour/src/Services/StarterKitService.php b/modules/acquia_cms_tour/src/Services/StarterKitService.php index a9bc889f1..ce3402ad7 100644 --- a/modules/acquia_cms_tour/src/Services/StarterKitService.php +++ b/modules/acquia_cms_tour/src/Services/StarterKitService.php @@ -77,7 +77,7 @@ public function __construct( * @param string $content_model * Variable holding the content model option selected. */ - public function enableModules(string $starter_kit, string $demo_question = NULL, string $content_model = NULL) { + public function enableModules(string $starter_kit, ?string $demo_question = NULL, ?string $content_model = NULL) { $starter_kits = [ 'acquia_cms_enterprise_low_code' => 'Acquia CMS Enterprise low-code', 'acquia_cms_community' => 'Acquia CMS Community', @@ -144,7 +144,7 @@ public static function enableSingleModule(string $module) { * @param string $content_model * Variable holding the content model option selected. */ - public function getModulesAndThemes(string $starter_kit, string $demo_question = NULL, string $content_model = NULL) { + public function getModulesAndThemes(string $starter_kit, ?string $demo_question = NULL, ?string $content_model = NULL) { $enableModules = $enableThemes = []; switch ($starter_kit) { case 'acquia_cms_enterprise_low_code': @@ -227,7 +227,7 @@ public function getModulesAndThemes(string $starter_kit, string $demo_question = * @param string $content_model * Variable holding the content model option selected. */ - public function getMissingModules(string $starter_kit, string $demo_question = NULL, string $content_model = NULL) { + public function getMissingModules(string $starter_kit, ?string $demo_question = NULL, ?string $content_model = NULL) { $modulesAndThemes = $this->getModulesAndThemes($starter_kit, $demo_question, $content_model); $modules = $modulesAndThemes['enableModules']; $moduleList = array_keys($this->moduleExtensionList->getList()); diff --git a/modules/acquia_cms_tour/tests/src/Functional/AcquiaGoogleMapsTest.php b/modules/acquia_cms_tour/tests/src/Functional/AcquiaGoogleMapsTest.php index f4eadac42..431acd8ca 100644 --- a/modules/acquia_cms_tour/tests/src/Functional/AcquiaGoogleMapsTest.php +++ b/modules/acquia_cms_tour/tests/src/Functional/AcquiaGoogleMapsTest.php @@ -2,8 +2,8 @@ namespace Drupal\Tests\acquia_cms_tour\Functional; -use Drupal\geocoder\Entity\GeocoderProvider; use Drupal\Tests\BrowserTestBase; +use Drupal\geocoder\Entity\GeocoderProvider; /** * Tests the Acquia CMS Tour module's integration with Google Maps. @@ -24,7 +24,7 @@ class AcquiaGoogleMapsTest extends BrowserTestBase { */ protected static $modules = [ 'acquia_cms_tour', - 'acquia_cms_place', + 'geocoder', ]; /** From e0957107ff6b4613406311301d38f191cc19155a Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Fri, 20 Dec 2024 18:47:31 +0530 Subject: [PATCH 02/14] ACMS-4373: Acquia Starter Kit Tour fix failing tests. --- .../acquia_cms_tour/acquia_cms_tour.install | 3 +-- .../src/Functional/AcquiaGoogleMapsTest.php | 26 +++++++++++++++++-- .../tests/src/Functional/GoogleTagManager.php | 18 ++----------- .../src/Functional/HelpIntegrationTest.php | 15 ----------- .../tests/src/Functional/RecaptchaTest.php | 15 ----------- .../src/Kernel/AcquiaTourDashboardTest.php | 15 ----------- 6 files changed, 27 insertions(+), 65 deletions(-) diff --git a/modules/acquia_cms_tour/acquia_cms_tour.install b/modules/acquia_cms_tour/acquia_cms_tour.install index c9c35aa76..d6e44b029 100644 --- a/modules/acquia_cms_tour/acquia_cms_tour.install +++ b/modules/acquia_cms_tour/acquia_cms_tour.install @@ -12,8 +12,7 @@ use Drupal\user\Entity\Role; */ function acquia_cms_tour_install($is_syncing) { if (!$is_syncing) { - $role = Role::load('content_administrator'); - if ($role) { + if (Role::load('content_administrator')) { user_role_grant_permissions('content_administrator', ['access acquia cms tour dashboard']); } } diff --git a/modules/acquia_cms_tour/tests/src/Functional/AcquiaGoogleMapsTest.php b/modules/acquia_cms_tour/tests/src/Functional/AcquiaGoogleMapsTest.php index 431acd8ca..e28a82747 100644 --- a/modules/acquia_cms_tour/tests/src/Functional/AcquiaGoogleMapsTest.php +++ b/modules/acquia_cms_tour/tests/src/Functional/AcquiaGoogleMapsTest.php @@ -48,6 +48,28 @@ class AcquiaGoogleMapsTest extends BrowserTestBase { public function testAcquiaGoogleMaps() { $assert_session = $this->assertSession(); + // Create an administrator account with all permissions. + $admin_user = $this->drupalCreateUser([], NULL, TRUE); + + // Log in the administrator account. + $this->drupalLogin($admin_user); + + $this->drupalGet('/admin/config/system/geocoder/geocoder-provider'); + $assert_session->statusCodeEquals(200); + // Select googlemaps option from dropdown. + $assert_session->elementExists('css', '[data-drupal-selector="edit-geocoder-provider"]') + ->selectOption('googlemaps'); + $assert_session->buttonExists('Add')->press(); + $assert_session->pageTextContains('Add a Geocoder provider'); + + $container = $assert_session->elementExists('css', '[data-drupal-selector="geocoder-provider-add-form"]'); + $container->fillField('edit-label', 'GoogleMaps'); + $container->fillField('edit-id', 'googlemaps'); + $container->fillField('edit-apikey', 'oldkey12345'); + $container->pressButton('Save'); + $assert_session->pageTextContains('Created new geocoder provider'); + + // Create user account with 'access acquia cms tour dashboard' permission. $account = $this->drupalCreateUser(['access acquia cms tour dashboard']); $this->drupalLogin($account); @@ -56,8 +78,8 @@ public function testAcquiaGoogleMaps() { $assert_session->statusCodeEquals(200); $container = $assert_session->elementExists('css', '[data-drupal-selector="edit-geocoder"]'); - // API key should be blank to start. - $assert_session->fieldValueEquals('maps_api_key', '', $container); + $assert_session->fieldValueEquals('maps_api_key', 'oldkey12345', $container); + $container->fillField('maps_api_key', ''); $container->pressButton('Save'); $assert_session->pageTextContains('Maps API key field is required.'); diff --git a/modules/acquia_cms_tour/tests/src/Functional/GoogleTagManager.php b/modules/acquia_cms_tour/tests/src/Functional/GoogleTagManager.php index d7084745a..712218028 100644 --- a/modules/acquia_cms_tour/tests/src/Functional/GoogleTagManager.php +++ b/modules/acquia_cms_tour/tests/src/Functional/GoogleTagManager.php @@ -25,21 +25,6 @@ class GoogleTagManager extends BrowserTestBase { 'google_tag', ]; - /** - * Disable strict config schema checks in this test. - * - * Cohesion has a lot of config schema errors, and until they are all fixed, - * this test cannot pass unless we disable strict config schema checking - * altogether. Since strict config schema isn't critically important in - * testing this functionality, it's okay to disable it for now, but it should - * be re-enabled (i.e., this property should be removed) as soon as possible. - * - * @var bool - */ - // @codingStandardsIgnoreStart - protected $strictConfigSchema = FALSE; - // @codingStandardsIgnoreEnd - /** * Tests the Google Tag Manager Form. */ @@ -61,7 +46,8 @@ public function testGoogleTagManager() { $container->pressButton('Save'); $assert_session->pageTextContains('The configuration options have been saved.'); // Test that the config values we expect are set correctly. - $tag_id = $this->config($this->config('google_tag.settings')->get('default_google_tag_entity'))->get('tag_container_ids'); + $tag = $this->config('google_tag.settings')->get('default_google_tag_entity'); + $tag_id = $this->config('google_tag.container.' . $tag)->get('tag_container_ids'); $this->assertEquals($tag_id, [$dummy_tag]); } diff --git a/modules/acquia_cms_tour/tests/src/Functional/HelpIntegrationTest.php b/modules/acquia_cms_tour/tests/src/Functional/HelpIntegrationTest.php index 3866da06f..0060fc8f7 100644 --- a/modules/acquia_cms_tour/tests/src/Functional/HelpIntegrationTest.php +++ b/modules/acquia_cms_tour/tests/src/Functional/HelpIntegrationTest.php @@ -26,21 +26,6 @@ class HelpIntegrationTest extends BrowserTestBase { 'toolbar', ]; - /** - * Disable strict config schema checks in this test. - * - * Scheduler has a config schema errors, and until it's fixed, - * this test cannot pass unless we disable strict config schema checking - * altogether. Since strict config schema isn't critically important in - * testing this functionality, it's okay to disable it for now, but it should - * be re-enabled (i.e., this property should be removed) as soon as possible. - * - * @var bool - */ - // @codingStandardsIgnoreStart - protected $strictConfigSchema = FALSE; - // @codingStandardsIgnoreEnd - /** * Tests the Acquia CMS Tour module's integration with the core Help module. */ diff --git a/modules/acquia_cms_tour/tests/src/Functional/RecaptchaTest.php b/modules/acquia_cms_tour/tests/src/Functional/RecaptchaTest.php index d6a9d45fa..6f5c7c228 100644 --- a/modules/acquia_cms_tour/tests/src/Functional/RecaptchaTest.php +++ b/modules/acquia_cms_tour/tests/src/Functional/RecaptchaTest.php @@ -25,21 +25,6 @@ class RecaptchaTest extends BrowserTestBase { 'recaptcha', ]; - /** - * Disable strict config schema checks in this test. - * - * Cohesion has a lot of config schema errors, and until they are all fixed, - * this test cannot pass unless we disable strict config schema checking - * altogether. Since strict config schema isn't critically important in - * testing this functionality, it's okay to disable it for now, but it should - * be re-enabled (i.e., this property should be removed) as soon as possible. - * - * @var bool - */ - // @codingStandardsIgnoreStart - protected $strictConfigSchema = FALSE; - // @codingStandardsIgnoreEnd - /** * Tests the Recaptcha Form. */ diff --git a/modules/acquia_cms_tour/tests/src/Kernel/AcquiaTourDashboardTest.php b/modules/acquia_cms_tour/tests/src/Kernel/AcquiaTourDashboardTest.php index dd86497aa..5d6f4fc9e 100644 --- a/modules/acquia_cms_tour/tests/src/Kernel/AcquiaTourDashboardTest.php +++ b/modules/acquia_cms_tour/tests/src/Kernel/AcquiaTourDashboardTest.php @@ -22,21 +22,6 @@ class AcquiaTourDashboardTest extends KernelTestBase { 'acquia_cms_tour', ]; - /** - * Disable strict config schema checks in this test. - * - * Cohesion has a lot of config schema errors, and until they are all fixed, - * this test cannot pass unless we disable strict config schema checking - * altogether. Since strict config schema isn't critically important in - * testing this functionality, it's okay to disable it for now, but it should - * be re-enabled (i.e., this property should be removed) as soon as possible. - * - * @var bool - */ - // @codingStandardsIgnoreStart - protected $strictConfigSchema = FALSE; - // @codingStandardsIgnoreEnd - /** * Tests AcquiaCMSTour plugins and make sure they are sorted per weights. */ From 52583c83b0af903b2a855200231f8d232dc01e92 Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Mon, 23 Dec 2024 10:38:24 +0530 Subject: [PATCH 03/14] ACMS-4373: Acquia Starter Kit Tour add google maps dev dependency. --- composer.lock | 21 +++++++++++---------- modules/acquia_cms_tour/composer.json | 3 ++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/composer.lock b/composer.lock index e6f6e1c1b..8f57c4670 100644 --- a/composer.lock +++ b/composer.lock @@ -2921,7 +2921,7 @@ "dist": { "type": "path", "url": "./modules/acquia_cms_toolbar", - "reference": "be6fe88d08fdf50135d62a79fc3217b69bc6aa6b" + "reference": "d6cd7d13ed41934d7654920ccb8a751972a28be6" }, "require": { "acquia/drupal-environment-detector": "^1.5", @@ -2950,7 +2950,7 @@ "dist": { "type": "path", "url": "./modules/acquia_cms_tour", - "reference": "63b34fbe25350ae4caed0d0232b3de2dff6f400f" + "reference": "f4cea1338093f3bd87095843583036f0bf289ecf" }, "require": { "drupal/checklistapi": "^2.1" @@ -2958,7 +2958,8 @@ "require-dev": { "drupal/geocoder": "^3.35 || ^4.10", "drupal/google_tag": "^2", - "drupal/recaptcha": "^3" + "drupal/recaptcha": "^3", + "geocoder-php/google-maps-provider": "^4.7" }, "type": "drupal-module", "extra": { @@ -5134,17 +5135,17 @@ }, { "name": "drupal/geocoder", - "version": "4.25.0", + "version": "4.26.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/geocoder.git", - "reference": "8.x-4.25" + "reference": "8.x-4.26" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/geocoder-8.x-4.25.zip", - "reference": "8.x-4.25", - "shasum": "f62dcbdb3c27a266aed92f78c6b861ffaa391ff0" + "url": "https://ftp.drupal.org/files/projects/geocoder-8.x-4.26.zip", + "reference": "8.x-4.26", + "shasum": "6681f565880da40341aa90b7e2df18bb1978fc96" }, "require": { "davedevelopment/stiphle": "^0.9.2", @@ -5188,8 +5189,8 @@ "type": "drupal-module", "extra": { "drupal": { - "version": "8.x-4.25", - "datestamp": "1722204762", + "version": "8.x-4.26", + "datestamp": "1733783003", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" diff --git a/modules/acquia_cms_tour/composer.json b/modules/acquia_cms_tour/composer.json index 44c209835..36f0f25ef 100644 --- a/modules/acquia_cms_tour/composer.json +++ b/modules/acquia_cms_tour/composer.json @@ -9,7 +9,8 @@ "require-dev": { "drupal/geocoder": "^3.35 || ^4.10", "drupal/google_tag": "^2", - "drupal/recaptcha": "^3" + "drupal/recaptcha": "^3", + "geocoder-php/google-maps-provider": "^4.7" }, "config": { "allow-plugins": { From fd16a6896ace15027dd03fdbf3d497fb1b765db9 Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Mon, 23 Dec 2024 14:23:23 +0530 Subject: [PATCH 04/14] ACMS-4373: Acquia Starter Kit Tour and Toolbar refactor install and entity_insert hooks. --- .../acquia_cms_toolbar.install | 11 +++++++++-- .../acquia_cms_toolbar.module | 3 ++- .../acquia_cms_tour/acquia_cms_tour.install | 4 ++-- modules/acquia_cms_tour/acquia_cms_tour.module | 3 ++- .../src/Form/AcquiaCmsDashboardBase.php | 18 +++++++++++++++--- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/modules/acquia_cms_toolbar/acquia_cms_toolbar.install b/modules/acquia_cms_toolbar/acquia_cms_toolbar.install index 2490ee368..dc7569bbf 100644 --- a/modules/acquia_cms_toolbar/acquia_cms_toolbar.install +++ b/modules/acquia_cms_toolbar/acquia_cms_toolbar.install @@ -12,7 +12,14 @@ use Drupal\user\Entity\Role; */ function acquia_cms_toolbar_install($is_syncing) { if (!$is_syncing) { - $roles = Role::loadMultiple(); + $roles = \Drupal::entityTypeManager()->getStorage('user_role')->loadMultiple([ + 'content_administrator', + 'content_author', + 'content_editor', + 'developer', + 'site_builder', + 'user_administrator', + ]); foreach ($roles as $role) { switch ($role->id()) { case 'content_administrator': @@ -21,7 +28,7 @@ function acquia_cms_toolbar_install($is_syncing) { case 'developer': case 'site_builder': case 'user_administrator': - user_role_grant_permissions($role->id(), ['access toolbar']); + $role->grantPermission('access toolbar')->trustData()->save(); break; } } diff --git a/modules/acquia_cms_toolbar/acquia_cms_toolbar.module b/modules/acquia_cms_toolbar/acquia_cms_toolbar.module index c57335f43..8e69a9404 100644 --- a/modules/acquia_cms_toolbar/acquia_cms_toolbar.module +++ b/modules/acquia_cms_toolbar/acquia_cms_toolbar.module @@ -112,7 +112,8 @@ function acquia_cms_toolbar_entity_insert(EntityInterface $entity) { case 'developer': case 'site_builder': case 'user_administrator': - user_role_grant_permissions($entity->id(), ['access toolbar']); + $role = \Drupal::entityTypeManager()->getStorage('user_role')->load($entity->id()); + $role->grantPermission('access toolbar')->trustData()->save(); break; } } diff --git a/modules/acquia_cms_tour/acquia_cms_tour.install b/modules/acquia_cms_tour/acquia_cms_tour.install index d6e44b029..e53385eff 100644 --- a/modules/acquia_cms_tour/acquia_cms_tour.install +++ b/modules/acquia_cms_tour/acquia_cms_tour.install @@ -12,8 +12,8 @@ use Drupal\user\Entity\Role; */ function acquia_cms_tour_install($is_syncing) { if (!$is_syncing) { - if (Role::load('content_administrator')) { - user_role_grant_permissions('content_administrator', ['access acquia cms tour dashboard']); + if ($role = \Drupal::entityTypeManager()->getStorage('user_role')->load('content_administrator')) { + $role->grantPermission('access toolbar')->trustData()->save(); } } } diff --git a/modules/acquia_cms_tour/acquia_cms_tour.module b/modules/acquia_cms_tour/acquia_cms_tour.module index fd0b8b611..7a1ccf382 100644 --- a/modules/acquia_cms_tour/acquia_cms_tour.module +++ b/modules/acquia_cms_tour/acquia_cms_tour.module @@ -62,7 +62,8 @@ function acquia_cms_tour_modules_uninstalled(array $modules) { function acquia_cms_tour_entity_insert(EntityInterface $entity) { switch ($entity->id()) { case 'content_administrator': - user_role_grant_permissions('content_administrator', ['access acquia cms tour dashboard']); + $role = \Drupal::entityTypeManager()->getStorage('user_role')->load('content_administrator'); + $role->grantPermission('access acquia cms tour dashboard')->trustData()->save(); break; } } diff --git a/modules/acquia_cms_tour/src/Form/AcquiaCmsDashboardBase.php b/modules/acquia_cms_tour/src/Form/AcquiaCmsDashboardBase.php index 4e18ec406..d510a3bf1 100644 --- a/modules/acquia_cms_tour/src/Form/AcquiaCmsDashboardBase.php +++ b/modules/acquia_cms_tour/src/Form/AcquiaCmsDashboardBase.php @@ -3,6 +3,7 @@ namespace Drupal\acquia_cms_tour\Form; use Drupal\Core\Extension\InfoParserInterface; +use Drupal\Core\Extension\ModuleExtensionList; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\State\StateInterface; @@ -50,6 +51,13 @@ abstract class AcquiaCmsDashboardBase extends ConfigFormBase implements AcquiaDa */ protected $infoParser; + /** + * The module handler. + * + * @var \Drupal\Core\Extension\ModuleExtensionList + */ + protected $moduleList; + /** * Constructs a new AcquiaConnectorForm. * @@ -61,12 +69,15 @@ abstract class AcquiaCmsDashboardBase extends ConfigFormBase implements AcquiaDa * The link generator. * @param \Drupal\Core\Extension\InfoParserInterface $info_parser * The info file parser. + * @param \Drupal\Core\Extension\ModuleExtensionList $module_handler + * The module list. */ - public function __construct(StateInterface $state, ModuleHandlerInterface $module_handler, LinkGeneratorInterface $link_generator, InfoParserInterface $info_parser) { + public function __construct(StateInterface $state, ModuleHandlerInterface $module_handler, LinkGeneratorInterface $link_generator, InfoParserInterface $info_parser, ModuleExtensionList $module_list) { $this->state = $state; $this->moduleHandler = $module_handler; $this->linkGenerator = $link_generator; $this->infoParser = $info_parser; + $this->moduleList = $module_list; } /** @@ -77,7 +88,8 @@ public static function create(ContainerInterface $container) { $container->get('state'), $container->get('module_handler'), $container->get('link_generator'), - $container->get('info_parser') + $container->get('info_parser'), + $container->get('extension.list.module'), ); } @@ -101,7 +113,7 @@ public function getModule() { * Get human readable module name. */ public function getModuleName() { - return $this->moduleHandler->getName($this->module); + return $this->moduleList->getName($this->module); } /** From 7ebf1995c5d18df022ebad91643534466f022812 Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Tue, 24 Dec 2024 12:14:12 +0530 Subject: [PATCH 05/14] ACMS-4373: Update Google map tour plugin. --- .../src/Plugin/AcquiaCmsTour/GoogleMapsApiForm.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleMapsApiForm.php b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleMapsApiForm.php index 10eabf23d..a52543add 100644 --- a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleMapsApiForm.php +++ b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleMapsApiForm.php @@ -157,12 +157,14 @@ private function loadProvider() : ?GeocoderProviderInterface { public function submitForm(array &$form, FormStateInterface $form_state) { $maps_api_key = $form_state->getValue('maps_api_key'); - // Configure Google Maps API Key for both Site Studio and - // Geocoder module. - $this->config('cohesion.settings') - ->set('google_map_api_key', $maps_api_key) - ->save(TRUE); + // Configure Google Maps API Key for Site Studio module. + if ($this->moduleHandler->moduleExists('cohesion')) { + $this->config('cohesion.settings') + ->set('google_map_api_key', $maps_api_key) + ->save(TRUE); + } + // Configure Google Maps API Key for Geocoder module. $provider = $this->loadProvider(); if ($provider) { $configuration = $provider->get('configuration'); From 8104560632ca7936262cab28e175f6be70f8385c Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Thu, 26 Dec 2024 10:57:53 +0530 Subject: [PATCH 06/14] ACMS-4373: Review feedback changes for Toolbar. --- .../acquia_cms_toolbar.install | 43 +------------------ .../acquia_cms_toolbar.module | 35 ++++++++++----- 2 files changed, 26 insertions(+), 52 deletions(-) diff --git a/modules/acquia_cms_toolbar/acquia_cms_toolbar.install b/modules/acquia_cms_toolbar/acquia_cms_toolbar.install index dc7569bbf..77be5e126 100644 --- a/modules/acquia_cms_toolbar/acquia_cms_toolbar.install +++ b/modules/acquia_cms_toolbar/acquia_cms_toolbar.install @@ -5,53 +5,12 @@ * Contains hook code for the Acquia CMS Toolbar. */ -use Drupal\user\Entity\Role; - /** * Implements hook_install(). */ function acquia_cms_toolbar_install($is_syncing) { if (!$is_syncing) { - $roles = \Drupal::entityTypeManager()->getStorage('user_role')->loadMultiple([ - 'content_administrator', - 'content_author', - 'content_editor', - 'developer', - 'site_builder', - 'user_administrator', - ]); - foreach ($roles as $role) { - switch ($role->id()) { - case 'content_administrator': - case 'content_author': - case 'content_editor': - case 'developer': - case 'site_builder': - case 'user_administrator': - $role->grantPermission('access toolbar')->trustData()->save(); - break; - } - } - } -} - -/** - * Update role permission handler. - */ -function update_toolbar_role_permission() { - $get_all_roles = Role::loadMultiple(); - $roles = [ - 'content_administrator', - 'content_author', - 'content_editor', - 'developer', - 'site_builder', - 'user_administrator', - ]; - foreach ($roles as $role) { - if (isset($get_all_roles[$role])) { - user_role_grant_permissions($role, ['access toolbar']); - } + update_toolbar_role_permission(); } } diff --git a/modules/acquia_cms_toolbar/acquia_cms_toolbar.module b/modules/acquia_cms_toolbar/acquia_cms_toolbar.module index 8e69a9404..6f5a7b1ee 100644 --- a/modules/acquia_cms_toolbar/acquia_cms_toolbar.module +++ b/modules/acquia_cms_toolbar/acquia_cms_toolbar.module @@ -8,6 +8,7 @@ use Acquia\DrupalEnvironmentDetector\AcquiaDrupalEnvironmentDetector as Environment; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Url; +use Drupal\user\RoleInterface; /** * Implements hook_preprocess_HOOK(). @@ -105,15 +106,29 @@ function _acquia_cms_toolbar_get_environment_indicator_color_config(): array { * Implements hook_entity_insert(). */ function acquia_cms_toolbar_entity_insert(EntityInterface $entity) { - switch ($entity->id()) { - case 'content_administrator': - case 'content_author': - case 'content_editor': - case 'developer': - case 'site_builder': - case 'user_administrator': - $role = \Drupal::entityTypeManager()->getStorage('user_role')->load($entity->id()); - $role->grantPermission('access toolbar')->trustData()->save(); - break; + if($entity instanceof RoleInterface && !$entity->isSyncing()) { + update_toolbar_role_permission([$entity->id()]); + } +} + +/** + * Update role permission handler. + * + * @param array|null $role_ids + * + * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException + * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException + */ +function update_toolbar_role_permission(array $role_ids = NULL): void { + $roles = \Drupal::entityTypeManager()->getStorage('user_role')->loadMultiple($role_ids ?? [ + 'content_administrator', + 'content_author', + 'content_editor', + 'developer', + 'site_builder', + 'user_administrator', + ]); + foreach ($roles as $role) { + $role->grantPermission('access toolbar')->trustData()->save(); } } From a3d5e119780135fd02f6ffc7a79fda94d2ff6ce0 Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Thu, 26 Dec 2024 12:06:35 +0530 Subject: [PATCH 07/14] ACMS-4373: Add test coverage to Toolbar module. --- .../acquia_cms_toolbar.install | 10 +- .../acquia_cms_toolbar.module | 5 +- .../EntityInsertOperationInterface.php | 20 ++++ .../EntityOperations/PermissionManager.php | 52 +++++++++ .../tests/src/Functional/PermissionsTest.php | 101 ++++++++++++++++++ 5 files changed, 185 insertions(+), 3 deletions(-) create mode 100644 modules/acquia_cms_toolbar/src/EntityOperations/EntityInsertOperationInterface.php create mode 100644 modules/acquia_cms_toolbar/src/EntityOperations/PermissionManager.php create mode 100644 modules/acquia_cms_toolbar/tests/src/Functional/PermissionsTest.php diff --git a/modules/acquia_cms_toolbar/acquia_cms_toolbar.install b/modules/acquia_cms_toolbar/acquia_cms_toolbar.install index 77be5e126..95817c314 100644 --- a/modules/acquia_cms_toolbar/acquia_cms_toolbar.install +++ b/modules/acquia_cms_toolbar/acquia_cms_toolbar.install @@ -5,12 +5,16 @@ * Contains hook code for the Acquia CMS Toolbar. */ +use Drupal\acquia_cms_toolbar\EntityOperations\PermissionManager; + /** * Implements hook_install(). */ function acquia_cms_toolbar_install($is_syncing) { if (!$is_syncing) { - update_toolbar_role_permission(); + $class_resolver = \Drupal::service('class_resolver'); + $class_resolver->getInstanceFromDefinition(PermissionManager::class) + ->grantPermissionToRoles(); } } @@ -18,5 +22,7 @@ function acquia_cms_toolbar_install($is_syncing) { * Update role permissions. */ function acquia_cms_toolbar_update_8001() { - update_toolbar_role_permission(); + $class_resolver = \Drupal::service('class_resolver'); + $class_resolver->getInstanceFromDefinition(PermissionManager::class) + ->grantPermissionToRoles(); } diff --git a/modules/acquia_cms_toolbar/acquia_cms_toolbar.module b/modules/acquia_cms_toolbar/acquia_cms_toolbar.module index 6f5a7b1ee..0b2316d18 100644 --- a/modules/acquia_cms_toolbar/acquia_cms_toolbar.module +++ b/modules/acquia_cms_toolbar/acquia_cms_toolbar.module @@ -8,6 +8,7 @@ use Acquia\DrupalEnvironmentDetector\AcquiaDrupalEnvironmentDetector as Environment; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Url; +use Drupal\acquia_cms_toolbar\EntityOperations\PermissionManager; use Drupal\user\RoleInterface; /** @@ -107,7 +108,9 @@ function _acquia_cms_toolbar_get_environment_indicator_color_config(): array { */ function acquia_cms_toolbar_entity_insert(EntityInterface $entity) { if($entity instanceof RoleInterface && !$entity->isSyncing()) { - update_toolbar_role_permission([$entity->id()]); + $class_resolver = \Drupal::service('class_resolver'); + $class_resolver->getInstanceFromDefinition(PermissionManager::class) + ->grantPermissionToRoles([$entity->id()]); } } diff --git a/modules/acquia_cms_toolbar/src/EntityOperations/EntityInsertOperationInterface.php b/modules/acquia_cms_toolbar/src/EntityOperations/EntityInsertOperationInterface.php new file mode 100644 index 000000000..ecb4322d9 --- /dev/null +++ b/modules/acquia_cms_toolbar/src/EntityOperations/EntityInsertOperationInterface.php @@ -0,0 +1,20 @@ +get('entity_type.manager') + ); + } + + /** + * {@inheritdoc} + */ + public function grantPermissionToRoles(array $role_ids = NULL): void { + $roles = \Drupal::entityTypeManager()->getStorage('user_role')->loadMultiple($role_ids ?? [ + 'content_administrator', + 'content_author', + 'content_editor', + 'developer', + 'site_builder', + 'user_administrator', + ]); + foreach ($roles as $role) { + $role->grantPermission('access toolbar')->trustData()->save(); + } + } + +} diff --git a/modules/acquia_cms_toolbar/tests/src/Functional/PermissionsTest.php b/modules/acquia_cms_toolbar/tests/src/Functional/PermissionsTest.php new file mode 100644 index 000000000..5accae63a --- /dev/null +++ b/modules/acquia_cms_toolbar/tests/src/Functional/PermissionsTest.php @@ -0,0 +1,101 @@ +drupalCreateRole([],'content_administrator'); + $this->entityTypeManager = $this->container->get("entity_type.manager"); + } + + /** + * Tests permissions are granted to content_administrator role. + */ + public function testGrantPermissionsOnInstall(): void { + // Load the role and check its permissions. + $role_permissions = $this->entityTypeManager->getStorage('user_role')->load('content_administrator')->getPermissions(); + $this->assertEquals(['access toolbar'], $role_permissions); + } + + /** + * Tests permissions are granted to role created after module install. + * + * @param string $role + * The role. + * @param array $permissions + * An array of permissions. + * + * @dataProvider rolePermissionDataProvider + */ + public function testGrantPermissionsOnRoleCreate(string $role, array $permissions): void { + // Create a new role. + $this->drupalCreateRole([], $role); + + // Load the role and check its permissions. + $role_permissions = $this->entityTypeManager->getStorage('user_role')->load('content_administrator')->getPermissions(); + $this->assertEquals($permissions, $role_permissions); + } + + /** + * Return an array of dataProvider for method grantPermissionToRoles. + */ + public static function rolePermissionDataProvider(): array { + return [ + [ + 'content_author', + ['access toolbar'], + ], + [ + 'content_editor', + ['access toolbar'], + ], + [ + 'developer', + ['access toolbar'], + ], + [ + 'site_builder', + ['access toolbar'], + ], + [ + 'user_administrator', + ['access toolbar'], + ], + ]; + } + +} From b882573b2ac69134976a6195cc6dd5696b7f0507 Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Thu, 26 Dec 2024 12:35:15 +0530 Subject: [PATCH 08/14] ACMS-4373: Rename google maps form and test to geocoder google maps. --- ...Form.php => GeocoderGoogleMapsApiForm.php} | 10 +++-- ...uiaGoogleMapsTest.php => GeocoderTest.php} | 38 ++++++++++--------- 2 files changed, 28 insertions(+), 20 deletions(-) rename modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/{GoogleMapsApiForm.php => GeocoderGoogleMapsApiForm.php} (95%) rename modules/acquia_cms_tour/tests/src/Functional/{AcquiaGoogleMapsTest.php => GeocoderTest.php} (73%) diff --git a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleMapsApiForm.php b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GeocoderGoogleMapsApiForm.php similarity index 95% rename from modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleMapsApiForm.php rename to modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GeocoderGoogleMapsApiForm.php index a52543add..b7fb7d99d 100644 --- a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleMapsApiForm.php +++ b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GeocoderGoogleMapsApiForm.php @@ -17,7 +17,7 @@ * weight = 2 * ) */ -class GoogleMapsApiForm extends AcquiaCmsDashboardBase { +class GeocoderGoogleMapsApiForm extends AcquiaCmsDashboardBase { /** * Provides module name. @@ -72,8 +72,12 @@ public function buildForm(array $form, FormStateInterface $form_state) { if ($this->isModuleEnabled()) { $module_path = $this->moduleHandler->getModule($module)->getPathname(); $module_info = $this->infoParser->parse($module_path); - $maps_api_key = $this->config('cohesion.settings') - ->get('google_map_api_key'); + + // Get Google Maps API Key from Site Studio config if available. + if ($this->moduleHandler->moduleExists('cohesion')) { + $maps_api_key = $this->config('cohesion.settings') + ->get('google_map_api_key'); + } $provider = $this->loadProvider(); if ($provider) { $configuration = $provider->get('configuration'); diff --git a/modules/acquia_cms_tour/tests/src/Functional/AcquiaGoogleMapsTest.php b/modules/acquia_cms_tour/tests/src/Functional/GeocoderTest.php similarity index 73% rename from modules/acquia_cms_tour/tests/src/Functional/AcquiaGoogleMapsTest.php rename to modules/acquia_cms_tour/tests/src/Functional/GeocoderTest.php index e28a82747..ac4197ed2 100644 --- a/modules/acquia_cms_tour/tests/src/Functional/AcquiaGoogleMapsTest.php +++ b/modules/acquia_cms_tour/tests/src/Functional/GeocoderTest.php @@ -6,13 +6,13 @@ use Drupal\geocoder\Entity\GeocoderProvider; /** - * Tests the Acquia CMS Tour module's integration with Google Maps. + * Tests the Acquia CMS Tour module's integration with Geocoder & Google Maps. * * @group acquia_cms * @group acquia_cms_tour * @group risky */ -class AcquiaGoogleMapsTest extends BrowserTestBase { +class GeocoderTest extends BrowserTestBase { /** * {@inheritdoc} @@ -28,24 +28,24 @@ class AcquiaGoogleMapsTest extends BrowserTestBase { ]; /** - * Disable strict config schema checks in this test. + * The module handler. * - * Cohesion has a lot of config schema errors, and until they are all fixed, - * this test cannot pass unless we disable strict config schema checking - * altogether. Since strict config schema isn't critically important in - * testing this functionality, it's okay to disable it for now, but it should - * be re-enabled (i.e., this property should be removed) as soon as possible. - * - * @var bool + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** + * {@inheritdoc} */ - // @codingStandardsIgnoreStart - protected $strictConfigSchema = FALSE; - // @codingStandardsIgnoreEnd + protected function setUp(): void { + parent::setUp(); + $this->moduleHandler = $this->container->get("module_handler"); + } /** * Tests that the Google Maps API key can be set on the tour page. */ - public function testAcquiaGoogleMaps() { + public function testGeocoderGoogleMaps() { $assert_session = $this->assertSession(); // Create an administrator account with all permissions. @@ -56,6 +56,7 @@ public function testAcquiaGoogleMaps() { $this->drupalGet('/admin/config/system/geocoder/geocoder-provider'); $assert_session->statusCodeEquals(200); + // Select googlemaps option from dropdown. $assert_session->elementExists('css', '[data-drupal-selector="edit-geocoder-provider"]') ->selectOption('googlemaps'); @@ -89,9 +90,12 @@ public function testAcquiaGoogleMaps() { $container->pressButton('Save'); $assert_session->pageTextContains('The Google Maps API key has been set.'); - // Now test that the config values we expect are set correctly. - $cohesion_map_key = $this->config('cohesion.settings')->get('google_map_api_key'); - $this->assertSame($cohesion_map_key, $dummy_key); + // Test that the config values we expect are set correctly for Site Studio. + if ($this->moduleHandler->moduleExists('cohesion')) { + $cohesion_map_key = $this->config('cohesion.settings')->get('google_map_api_key'); + $this->assertSame($cohesion_map_key, $dummy_key); + } + $configuration = GeocoderProvider::load('googlemaps')->get('configuration'); $this->assertSame($configuration['apiKey'], $dummy_key); From 8a65096845829b2557d7f4f78e1c5c2a30d585dc Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Thu, 26 Dec 2024 13:42:31 +0530 Subject: [PATCH 09/14] ACMS-4373: Add permission test coverage to Tour module. --- .../acquia_cms_tour/acquia_cms_tour.install | 5 +- .../acquia_cms_tour/acquia_cms_tour.module | 12 +++-- .../tests/src/Functional/PermissionsTest.php | 53 +++++++++++++++++++ 3 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 modules/acquia_cms_tour/tests/src/Functional/PermissionsTest.php diff --git a/modules/acquia_cms_tour/acquia_cms_tour.install b/modules/acquia_cms_tour/acquia_cms_tour.install index e53385eff..439faaba9 100644 --- a/modules/acquia_cms_tour/acquia_cms_tour.install +++ b/modules/acquia_cms_tour/acquia_cms_tour.install @@ -12,8 +12,9 @@ use Drupal\user\Entity\Role; */ function acquia_cms_tour_install($is_syncing) { if (!$is_syncing) { - if ($role = \Drupal::entityTypeManager()->getStorage('user_role')->load('content_administrator')) { - $role->grantPermission('access toolbar')->trustData()->save(); + $role = \Drupal::entityTypeManager()->getStorage('user_role')->load('content_administrator'); + if($role) { + $role->grantPermission('access acquia cms tour dashboard')->trustData()->save(); } } } diff --git a/modules/acquia_cms_tour/acquia_cms_tour.module b/modules/acquia_cms_tour/acquia_cms_tour.module index 7a1ccf382..7aae2390a 100644 --- a/modules/acquia_cms_tour/acquia_cms_tour.module +++ b/modules/acquia_cms_tour/acquia_cms_tour.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Entity\EntityInterface; +use Drupal\user\RoleInterface; /** * Implements hook_menu_links_discovered_alter(). @@ -60,10 +61,11 @@ function acquia_cms_tour_modules_uninstalled(array $modules) { * Implements hook_cms_tour_entity_insert(). */ function acquia_cms_tour_entity_insert(EntityInterface $entity) { - switch ($entity->id()) { - case 'content_administrator': - $role = \Drupal::entityTypeManager()->getStorage('user_role')->load('content_administrator'); - $role->grantPermission('access acquia cms tour dashboard')->trustData()->save(); - break; + if($entity instanceof RoleInterface && + !$entity->isSyncing() && + $entity->id() == 'content_administrator' + ) { + $role = \Drupal::entityTypeManager()->getStorage('user_role')->load('content_administrator'); + $role->grantPermission('access acquia cms tour dashboard')->trustData()->save(); } } diff --git a/modules/acquia_cms_tour/tests/src/Functional/PermissionsTest.php b/modules/acquia_cms_tour/tests/src/Functional/PermissionsTest.php new file mode 100644 index 000000000..465421275 --- /dev/null +++ b/modules/acquia_cms_tour/tests/src/Functional/PermissionsTest.php @@ -0,0 +1,53 @@ +drupalCreateRole([],'content_administrator'); + $this->entityTypeManager = $this->container->get("entity_type.manager"); + } + + /** + * Tests permissions are granted to content_administrator role. + */ + public function testGrantPermissionsOnInstall(): void { + // Load the role and check its permissions. + $role_permissions = $this->entityTypeManager->getStorage('user_role')->load('content_administrator')->getPermissions(); + $this->assertEquals(['access acquia cms tour dashboard'], $role_permissions); + } + +} From 033a89683376325e30116e1c62dbe85f5698b995 Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Thu, 26 Dec 2024 14:17:40 +0530 Subject: [PATCH 10/14] ACMS-4373: Refactore code and add toolbar test in CI. --- .github/workflows/acquia_cms_ci.workflow.yml | 1 + .github/workflows/acquia_cms_cron.yml | 1 + .../acquia_cms_toolbar.module | 28 ++----------------- .../EntityOperations/PermissionManager.php | 2 +- .../acquia_cms_tour/acquia_cms_tour.module | 7 ++--- 5 files changed, 9 insertions(+), 30 deletions(-) diff --git a/.github/workflows/acquia_cms_ci.workflow.yml b/.github/workflows/acquia_cms_ci.workflow.yml index cde428f6c..84a694c9d 100644 --- a/.github/workflows/acquia_cms_ci.workflow.yml +++ b/.github/workflows/acquia_cms_ci.workflow.yml @@ -240,6 +240,7 @@ jobs: - acquia_cms_place - acquia_cms_search - acquia_cms_site_studio + - acquia_cms_toolbar - acquia_cms_tour - acquia_cms_video steps: diff --git a/.github/workflows/acquia_cms_cron.yml b/.github/workflows/acquia_cms_cron.yml index c405d6458..6f52ab32e 100644 --- a/.github/workflows/acquia_cms_cron.yml +++ b/.github/workflows/acquia_cms_cron.yml @@ -383,6 +383,7 @@ jobs: - acquia_cms_place - acquia_cms_search - acquia_cms_site_studio + - acquia_cms_toolbar - acquia_cms_tour - acquia_cms_video steps: diff --git a/modules/acquia_cms_toolbar/acquia_cms_toolbar.module b/modules/acquia_cms_toolbar/acquia_cms_toolbar.module index 0b2316d18..aafd15256 100644 --- a/modules/acquia_cms_toolbar/acquia_cms_toolbar.module +++ b/modules/acquia_cms_toolbar/acquia_cms_toolbar.module @@ -106,32 +106,10 @@ function _acquia_cms_toolbar_get_environment_indicator_color_config(): array { /** * Implements hook_entity_insert(). */ -function acquia_cms_toolbar_entity_insert(EntityInterface $entity) { - if($entity instanceof RoleInterface && !$entity->isSyncing()) { +function acquia_cms_toolbar_user_role_insert(RoleInterface $role) { + if(!$role->isSyncing()) { $class_resolver = \Drupal::service('class_resolver'); $class_resolver->getInstanceFromDefinition(PermissionManager::class) - ->grantPermissionToRoles([$entity->id()]); - } -} - -/** - * Update role permission handler. - * - * @param array|null $role_ids - * - * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException - * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException - */ -function update_toolbar_role_permission(array $role_ids = NULL): void { - $roles = \Drupal::entityTypeManager()->getStorage('user_role')->loadMultiple($role_ids ?? [ - 'content_administrator', - 'content_author', - 'content_editor', - 'developer', - 'site_builder', - 'user_administrator', - ]); - foreach ($roles as $role) { - $role->grantPermission('access toolbar')->trustData()->save(); + ->grantPermissionToRoles([$role->id()]); } } diff --git a/modules/acquia_cms_toolbar/src/EntityOperations/PermissionManager.php b/modules/acquia_cms_toolbar/src/EntityOperations/PermissionManager.php index 0e7d3be58..cdf2bc7be 100644 --- a/modules/acquia_cms_toolbar/src/EntityOperations/PermissionManager.php +++ b/modules/acquia_cms_toolbar/src/EntityOperations/PermissionManager.php @@ -36,7 +36,7 @@ public static function create(ContainerInterface $container) { * {@inheritdoc} */ public function grantPermissionToRoles(array $role_ids = NULL): void { - $roles = \Drupal::entityTypeManager()->getStorage('user_role')->loadMultiple($role_ids ?? [ + $roles = $this->entityTypeManager->getStorage('user_role')->loadMultiple($role_ids ?? [ 'content_administrator', 'content_author', 'content_editor', diff --git a/modules/acquia_cms_tour/acquia_cms_tour.module b/modules/acquia_cms_tour/acquia_cms_tour.module index 7aae2390a..e0a9808ef 100644 --- a/modules/acquia_cms_tour/acquia_cms_tour.module +++ b/modules/acquia_cms_tour/acquia_cms_tour.module @@ -60,10 +60,9 @@ function acquia_cms_tour_modules_uninstalled(array $modules) { /** * Implements hook_cms_tour_entity_insert(). */ -function acquia_cms_tour_entity_insert(EntityInterface $entity) { - if($entity instanceof RoleInterface && - !$entity->isSyncing() && - $entity->id() == 'content_administrator' +function acquia_cms_tour_user_role_insert(RoleInterface $role) { + if(!$role->isSyncing() && + $role->id() == 'content_administrator' ) { $role = \Drupal::entityTypeManager()->getStorage('user_role')->load('content_administrator'); $role->grantPermission('access acquia cms tour dashboard')->trustData()->save(); From ac9d7545062ed7fa2bc4bff912908e7a4e0694b9 Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Fri, 27 Dec 2024 13:22:10 +0530 Subject: [PATCH 11/14] ACMS-4373: Remove EntityInsertOperationInterface from toolbar. --- .../EntityInsertOperationInterface.php | 20 ------------------- .../EntityOperations/PermissionManager.php | 9 +++++++-- 2 files changed, 7 insertions(+), 22 deletions(-) delete mode 100644 modules/acquia_cms_toolbar/src/EntityOperations/EntityInsertOperationInterface.php diff --git a/modules/acquia_cms_toolbar/src/EntityOperations/EntityInsertOperationInterface.php b/modules/acquia_cms_toolbar/src/EntityOperations/EntityInsertOperationInterface.php deleted file mode 100644 index ecb4322d9..000000000 --- a/modules/acquia_cms_toolbar/src/EntityOperations/EntityInsertOperationInterface.php +++ /dev/null @@ -1,20 +0,0 @@ -entityTypeManager->getStorage('user_role')->loadMultiple($role_ids ?? [ From 9443e5d0b10b6ab8dbc6dda4d71b651e352e8707 Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Fri, 27 Dec 2024 13:53:56 +0530 Subject: [PATCH 12/14] ACMS-4373: Revert static code analysis as per ORCA. --- modules/acquia_cms_toolbar/acquia_cms_toolbar.module | 5 ++--- .../src/EntityOperations/PermissionManager.php | 2 +- .../tests/src/Functional/PermissionsTest.php | 4 ++-- modules/acquia_cms_tour/acquia_cms_tour.install | 2 +- modules/acquia_cms_tour/acquia_cms_tour.module | 3 +-- .../acquia_cms_tour/src/Controller/DashboardController.php | 4 ++-- modules/acquia_cms_tour/src/Form/AcquiaCmsDashboardBase.php | 2 +- modules/acquia_cms_tour/src/Form/InstallationWizardForm.php | 2 +- .../src/Form/StarterKitSelectionWizardForm.php | 2 +- .../src/Plugin/AcquiaCmsStarterKit/StarterKitConfigForm.php | 2 +- .../Plugin/AcquiaCmsStarterKit/StarterKitSelectionForm.php | 2 +- .../src/Plugin/AcquiaCmsTour/GeocoderGoogleMapsApiForm.php | 2 +- .../src/Plugin/AcquiaCmsTour/GoogleTagManagerForm.php | 2 +- .../src/Plugin/AcquiaCmsTour/RecaptchaForm.php | 2 +- .../acquia_cms_tour/tests/src/Functional/GeocoderTest.php | 3 +-- .../acquia_cms_tour/tests/src/Functional/PermissionsTest.php | 4 ++-- 16 files changed, 20 insertions(+), 23 deletions(-) diff --git a/modules/acquia_cms_toolbar/acquia_cms_toolbar.module b/modules/acquia_cms_toolbar/acquia_cms_toolbar.module index aafd15256..970c456b1 100644 --- a/modules/acquia_cms_toolbar/acquia_cms_toolbar.module +++ b/modules/acquia_cms_toolbar/acquia_cms_toolbar.module @@ -6,9 +6,8 @@ */ use Acquia\DrupalEnvironmentDetector\AcquiaDrupalEnvironmentDetector as Environment; -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Url; use Drupal\acquia_cms_toolbar\EntityOperations\PermissionManager; +use Drupal\Core\Url; use Drupal\user\RoleInterface; /** @@ -107,7 +106,7 @@ function _acquia_cms_toolbar_get_environment_indicator_color_config(): array { * Implements hook_entity_insert(). */ function acquia_cms_toolbar_user_role_insert(RoleInterface $role) { - if(!$role->isSyncing()) { + if (!$role->isSyncing()) { $class_resolver = \Drupal::service('class_resolver'); $class_resolver->getInstanceFromDefinition(PermissionManager::class) ->grantPermissionToRoles([$role->id()]); diff --git a/modules/acquia_cms_toolbar/src/EntityOperations/PermissionManager.php b/modules/acquia_cms_toolbar/src/EntityOperations/PermissionManager.php index 5e9d76764..b0c3c3bc3 100644 --- a/modules/acquia_cms_toolbar/src/EntityOperations/PermissionManager.php +++ b/modules/acquia_cms_toolbar/src/EntityOperations/PermissionManager.php @@ -40,7 +40,7 @@ public static function create(ContainerInterface $container) { * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ - public function grantPermissionToRoles(array $role_ids = NULL): void { + public function grantPermissionToRoles(?array $role_ids = NULL): void { $roles = $this->entityTypeManager->getStorage('user_role')->loadMultiple($role_ids ?? [ 'content_administrator', 'content_author', diff --git a/modules/acquia_cms_toolbar/tests/src/Functional/PermissionsTest.php b/modules/acquia_cms_toolbar/tests/src/Functional/PermissionsTest.php index 5accae63a..893cec8ad 100644 --- a/modules/acquia_cms_toolbar/tests/src/Functional/PermissionsTest.php +++ b/modules/acquia_cms_toolbar/tests/src/Functional/PermissionsTest.php @@ -18,7 +18,7 @@ class PermissionsTest extends BrowserTestBase { * {@inheritdoc} */ protected static $modules = [ - 'acquia_cms_toolbar' + 'acquia_cms_toolbar', ]; /** @@ -38,7 +38,7 @@ class PermissionsTest extends BrowserTestBase { */ protected function setUp(): void { parent::setUp(); - $this->drupalCreateRole([],'content_administrator'); + $this->drupalCreateRole([], 'content_administrator'); $this->entityTypeManager = $this->container->get("entity_type.manager"); } diff --git a/modules/acquia_cms_tour/acquia_cms_tour.install b/modules/acquia_cms_tour/acquia_cms_tour.install index 439faaba9..c17894737 100644 --- a/modules/acquia_cms_tour/acquia_cms_tour.install +++ b/modules/acquia_cms_tour/acquia_cms_tour.install @@ -13,7 +13,7 @@ use Drupal\user\Entity\Role; function acquia_cms_tour_install($is_syncing) { if (!$is_syncing) { $role = \Drupal::entityTypeManager()->getStorage('user_role')->load('content_administrator'); - if($role) { + if ($role) { $role->grantPermission('access acquia cms tour dashboard')->trustData()->save(); } } diff --git a/modules/acquia_cms_tour/acquia_cms_tour.module b/modules/acquia_cms_tour/acquia_cms_tour.module index e0a9808ef..ea24c3142 100644 --- a/modules/acquia_cms_tour/acquia_cms_tour.module +++ b/modules/acquia_cms_tour/acquia_cms_tour.module @@ -5,7 +5,6 @@ * Contains hook implementations for the acquia_cms_tour module. */ -use Drupal\Core\Entity\EntityInterface; use Drupal\user\RoleInterface; /** @@ -61,7 +60,7 @@ function acquia_cms_tour_modules_uninstalled(array $modules) { * Implements hook_cms_tour_entity_insert(). */ function acquia_cms_tour_user_role_insert(RoleInterface $role) { - if(!$role->isSyncing() && + if (!$role->isSyncing() && $role->id() == 'content_administrator' ) { $role = \Drupal::entityTypeManager()->getStorage('user_role')->load('content_administrator'); diff --git a/modules/acquia_cms_tour/src/Controller/DashboardController.php b/modules/acquia_cms_tour/src/Controller/DashboardController.php index 3c378b9ce..cb68b3e61 100644 --- a/modules/acquia_cms_tour/src/Controller/DashboardController.php +++ b/modules/acquia_cms_tour/src/Controller/DashboardController.php @@ -2,13 +2,13 @@ namespace Drupal\acquia_cms_tour\Controller; +use Drupal\acquia_cms_tour\AcquiaCmsTourManager; +use Drupal\acquia_cms_tour\Services\StarterKitService; use Drupal\Component\Serialization\Json; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\DependencyInjection\ClassResolverInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\Url; -use Drupal\acquia_cms_tour\AcquiaCmsTourManager; -use Drupal\acquia_cms_tour\Services\StarterKitService; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; diff --git a/modules/acquia_cms_tour/src/Form/AcquiaCmsDashboardBase.php b/modules/acquia_cms_tour/src/Form/AcquiaCmsDashboardBase.php index d510a3bf1..426901368 100644 --- a/modules/acquia_cms_tour/src/Form/AcquiaCmsDashboardBase.php +++ b/modules/acquia_cms_tour/src/Form/AcquiaCmsDashboardBase.php @@ -70,7 +70,7 @@ abstract class AcquiaCmsDashboardBase extends ConfigFormBase implements AcquiaDa * @param \Drupal\Core\Extension\InfoParserInterface $info_parser * The info file parser. * @param \Drupal\Core\Extension\ModuleExtensionList $module_handler - * The module list. + * The module list. */ public function __construct(StateInterface $state, ModuleHandlerInterface $module_handler, LinkGeneratorInterface $link_generator, InfoParserInterface $info_parser, ModuleExtensionList $module_list) { $this->state = $state; diff --git a/modules/acquia_cms_tour/src/Form/InstallationWizardForm.php b/modules/acquia_cms_tour/src/Form/InstallationWizardForm.php index 270e259f0..97047157f 100644 --- a/modules/acquia_cms_tour/src/Form/InstallationWizardForm.php +++ b/modules/acquia_cms_tour/src/Form/InstallationWizardForm.php @@ -2,13 +2,13 @@ namespace Drupal\acquia_cms_tour\Form; +use Drupal\acquia_cms_tour\AcquiaCmsTourManager; use Drupal\Core\DependencyInjection\ClassResolverInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; use Drupal\Core\Render\Renderer; use Drupal\Core\State\StateInterface; -use Drupal\acquia_cms_tour\AcquiaCmsTourManager; use Symfony\Component\DependencyInjection\ContainerInterface; /** diff --git a/modules/acquia_cms_tour/src/Form/StarterKitSelectionWizardForm.php b/modules/acquia_cms_tour/src/Form/StarterKitSelectionWizardForm.php index 68000d21f..f2dfe1ac3 100644 --- a/modules/acquia_cms_tour/src/Form/StarterKitSelectionWizardForm.php +++ b/modules/acquia_cms_tour/src/Form/StarterKitSelectionWizardForm.php @@ -2,13 +2,13 @@ namespace Drupal\acquia_cms_tour\Form; +use Drupal\acquia_cms_tour\AcquiaCmsStarterKitManager; use Drupal\Core\DependencyInjection\ClassResolverInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; use Drupal\Core\Render\Renderer; use Drupal\Core\State\StateInterface; -use Drupal\acquia_cms_tour\AcquiaCmsStarterKitManager; use Symfony\Component\DependencyInjection\ContainerInterface; /** diff --git a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsStarterKit/StarterKitConfigForm.php b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsStarterKit/StarterKitConfigForm.php index fac24c484..e8b784098 100644 --- a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsStarterKit/StarterKitConfigForm.php +++ b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsStarterKit/StarterKitConfigForm.php @@ -2,9 +2,9 @@ namespace Drupal\acquia_cms_tour\Plugin\AcquiaCmsStarterKit; +use Drupal\acquia_cms_tour\Form\AcquiaCmsStarterKitBase; use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Form\FormStateInterface; -use Drupal\acquia_cms_tour\Form\AcquiaCmsStarterKitBase; use Symfony\Component\DependencyInjection\ContainerInterface; /** diff --git a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsStarterKit/StarterKitSelectionForm.php b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsStarterKit/StarterKitSelectionForm.php index cd5cba434..bac080e73 100644 --- a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsStarterKit/StarterKitSelectionForm.php +++ b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsStarterKit/StarterKitSelectionForm.php @@ -2,9 +2,9 @@ namespace Drupal\acquia_cms_tour\Plugin\AcquiaCmsStarterKit; +use Drupal\acquia_cms_tour\Form\AcquiaCmsStarterKitBase; use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Form\FormStateInterface; -use Drupal\acquia_cms_tour\Form\AcquiaCmsStarterKitBase; use Symfony\Component\DependencyInjection\ContainerInterface; /** diff --git a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GeocoderGoogleMapsApiForm.php b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GeocoderGoogleMapsApiForm.php index b7fb7d99d..7cea2165a 100644 --- a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GeocoderGoogleMapsApiForm.php +++ b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GeocoderGoogleMapsApiForm.php @@ -2,9 +2,9 @@ namespace Drupal\acquia_cms_tour\Plugin\AcquiaCmsTour; +use Drupal\acquia_cms_tour\Form\AcquiaCmsDashboardBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; -use Drupal\acquia_cms_tour\Form\AcquiaCmsDashboardBase; use Drupal\geocoder\GeocoderProviderInterface; use Symfony\Component\DependencyInjection\ContainerInterface; diff --git a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleTagManagerForm.php b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleTagManagerForm.php index 15b71fe87..5121d92ad 100644 --- a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleTagManagerForm.php +++ b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/GoogleTagManagerForm.php @@ -2,10 +2,10 @@ namespace Drupal\acquia_cms_tour\Plugin\AcquiaCmsTour; +use Drupal\acquia_cms_tour\Form\AcquiaCmsDashboardBase; use Drupal\Component\Utility\Html; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; -use Drupal\acquia_cms_tour\Form\AcquiaCmsDashboardBase; use Drupal\google_tag\Entity\TagContainer; /** diff --git a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/RecaptchaForm.php b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/RecaptchaForm.php index 136774231..9ec748527 100644 --- a/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/RecaptchaForm.php +++ b/modules/acquia_cms_tour/src/Plugin/AcquiaCmsTour/RecaptchaForm.php @@ -2,9 +2,9 @@ namespace Drupal\acquia_cms_tour\Plugin\AcquiaCmsTour; +use Drupal\acquia_cms_tour\Form\AcquiaCmsDashboardBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; -use Drupal\acquia_cms_tour\Form\AcquiaCmsDashboardBase; /** * Plugin implementation of the acquia_cms_tour. diff --git a/modules/acquia_cms_tour/tests/src/Functional/GeocoderTest.php b/modules/acquia_cms_tour/tests/src/Functional/GeocoderTest.php index ac4197ed2..f06d70b5f 100644 --- a/modules/acquia_cms_tour/tests/src/Functional/GeocoderTest.php +++ b/modules/acquia_cms_tour/tests/src/Functional/GeocoderTest.php @@ -2,8 +2,8 @@ namespace Drupal\Tests\acquia_cms_tour\Functional; -use Drupal\Tests\BrowserTestBase; use Drupal\geocoder\Entity\GeocoderProvider; +use Drupal\Tests\BrowserTestBase; /** * Tests the Acquia CMS Tour module's integration with Geocoder & Google Maps. @@ -96,7 +96,6 @@ public function testGeocoderGoogleMaps() { $this->assertSame($cohesion_map_key, $dummy_key); } - $configuration = GeocoderProvider::load('googlemaps')->get('configuration'); $this->assertSame($configuration['apiKey'], $dummy_key); } diff --git a/modules/acquia_cms_tour/tests/src/Functional/PermissionsTest.php b/modules/acquia_cms_tour/tests/src/Functional/PermissionsTest.php index 465421275..bd95e8579 100644 --- a/modules/acquia_cms_tour/tests/src/Functional/PermissionsTest.php +++ b/modules/acquia_cms_tour/tests/src/Functional/PermissionsTest.php @@ -17,7 +17,7 @@ class PermissionsTest extends BrowserTestBase { * {@inheritdoc} */ protected static $modules = [ - 'acquia_cms_tour' + 'acquia_cms_tour', ]; /** @@ -37,7 +37,7 @@ class PermissionsTest extends BrowserTestBase { */ protected function setUp(): void { parent::setUp(); - $this->drupalCreateRole([],'content_administrator'); + $this->drupalCreateRole([], 'content_administrator'); $this->entityTypeManager = $this->container->get("entity_type.manager"); } From ac5ab956abcd5dba4f597126fa40ef8f9cf10c56 Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Fri, 27 Dec 2024 14:10:02 +0530 Subject: [PATCH 13/14] ACMS-4373: execute test on INTEGRATED_TEST_ON_PREVIOUS_MINOR will fix in ACMS-4400. --- .github/workflows/acquia_cms_ci.workflow.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/acquia_cms_ci.workflow.yml b/.github/workflows/acquia_cms_ci.workflow.yml index 84a694c9d..0e9d91c72 100644 --- a/.github/workflows/acquia_cms_ci.workflow.yml +++ b/.github/workflows/acquia_cms_ci.workflow.yml @@ -128,7 +128,8 @@ jobs: matrix: orca-job: - INTEGRATED_TEST_ON_LATEST_LTS - - ISOLATED_TEST_ON_CURRENT + - INTEGRATED_TEST_ON_PREVIOUS_MINOR +# - ISOLATED_TEST_ON_CURRENT acms_job: - integrated_php_unit_tests - integrated_existing_site_tests @@ -225,7 +226,8 @@ jobs: matrix: orca-job: - INTEGRATED_TEST_ON_LATEST_LTS - - ISOLATED_TEST_ON_CURRENT + - INTEGRATED_TEST_ON_PREVIOUS_MINOR +# - ISOLATED_TEST_ON_CURRENT #php-version: [ "8.1" ] modules: - acquia_cms_article @@ -323,14 +325,16 @@ jobs: matrix: orca-job: - INTEGRATED_TEST_ON_LATEST_LTS - # - INTEGRATED_TEST_ON_PREVIOUS_MINOR - - ISOLATED_TEST_ON_CURRENT + - INTEGRATED_TEST_ON_PREVIOUS_MINOR +# - ISOLATED_TEST_ON_CURRENT php-version: - 8.1 - 8.3 exclude: - php-version: 8.1 - orca-job: ISOLATED_TEST_ON_CURRENT + orca-job: INTEGRATED_TEST_ON_PREVIOUS_MINOR +# - php-version: 8.1 +# orca-job: ISOLATED_TEST_ON_CURRENT steps: - uses: actions/checkout@v4 - name: Use Node.js 20.x From e2ea37a9c7b5a0331aab5de781ec9bdf3ab64b9d Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Fri, 27 Dec 2024 14:34:45 +0530 Subject: [PATCH 14/14] ACMS-4373: Fix headless warnings related to D11 compatibility. --- .../AcquiaCmsHeadless/HeadlessApiKeys.php | 50 ++-------------- .../AcquiaCmsHeadless/HeadlessApiUsers.php | 52 ++-------------- .../HeadlessNextEntityTypes.php | 50 ++-------------- .../AcquiaCmsHeadless/HeadlessNextSites.php | 59 ++----------------- 4 files changed, 21 insertions(+), 190 deletions(-) diff --git a/modules/acquia_cms_headless/src/Plugin/AcquiaCmsHeadless/HeadlessApiKeys.php b/modules/acquia_cms_headless/src/Plugin/AcquiaCmsHeadless/HeadlessApiKeys.php index 5ca89eea2..9e29fc40e 100644 --- a/modules/acquia_cms_headless/src/Plugin/AcquiaCmsHeadless/HeadlessApiKeys.php +++ b/modules/acquia_cms_headless/src/Plugin/AcquiaCmsHeadless/HeadlessApiKeys.php @@ -25,34 +25,6 @@ * ) */ class HeadlessApiKeys extends AcquiaCmsDashboardBase { - /** - * The state interface. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; - - - /** - * The module handler. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** - * The link generator. - * - * @var \Drupal\Core\Utility\LinkGeneratorInterface - */ - protected $linkGenerator; - - /** - * The info file parser. - * - * @var \Drupal\Core\Extension\InfoParserInterface - */ - protected $infoParser; /** * The EntityTypeManager service. @@ -75,27 +47,15 @@ class HeadlessApiKeys extends AcquiaCmsDashboardBase { */ protected $module = 'consumers'; - /** - * {@inheritdoc} - */ - public function __construct(StateInterface $state, ModuleHandlerInterface $module_handler, LinkGeneratorInterface $link_generator, InfoParserInterface $info_parser, EntityTypeManagerInterface $entity_type_manager, StarterkitNextjsService $starterkit_nextjs_service) { - parent::__construct($state, $module_handler, $link_generator, $info_parser); - $this->entityTypeManager = $entity_type_manager; - $this->starterKitNextjsService = $starterkit_nextjs_service; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('state'), - $container->get('module_handler'), - $container->get('link_generator'), - $container->get('info_parser'), - $container->get('entity_type.manager'), - $container->get('acquia_cms_headless.starterkit_nextjs') - ); + $instance = parent::create($container); + $instance->entityTypeManager = $container->get('entity_type.manager'); + $instance->starterKitNextjsService = $container->get('acquia_cms_headless.starterkit_nextjs'); + + return $instance; } /** diff --git a/modules/acquia_cms_headless/src/Plugin/AcquiaCmsHeadless/HeadlessApiUsers.php b/modules/acquia_cms_headless/src/Plugin/AcquiaCmsHeadless/HeadlessApiUsers.php index 4c0ae9378..ca85797d1 100644 --- a/modules/acquia_cms_headless/src/Plugin/AcquiaCmsHeadless/HeadlessApiUsers.php +++ b/modules/acquia_cms_headless/src/Plugin/AcquiaCmsHeadless/HeadlessApiUsers.php @@ -24,34 +24,6 @@ * ) */ class HeadlessApiUsers extends AcquiaCmsDashboardBase { - /** - * The state interface. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; - - - /** - * The module handler. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** - * The link generator. - * - * @var \Drupal\Core\Utility\LinkGeneratorInterface - */ - protected $linkGenerator; - - /** - * The info file parser. - * - * @var \Drupal\Core\Extension\InfoParserInterface - */ - protected $infoParser; /** * The EntityTypeManager service. @@ -81,28 +53,16 @@ class HeadlessApiUsers extends AcquiaCmsDashboardBase { */ protected $headlessRoleLabel; - /** - * {@inheritdoc} - */ - public function __construct(StateInterface $state, ModuleHandlerInterface $module_handler, LinkGeneratorInterface $link_generator, InfoParserInterface $info_parser, EntityTypeManagerInterface $entity_type_manager, StarterkitNextjsService $starterkit_nextjs_service) { - parent::__construct($state, $module_handler, $link_generator, $info_parser); - $this->entityTypeManager = $entity_type_manager; - $this->headlessRoleLabel = $entity_type_manager->getStorage('user_role')->load('headless')->label(); - $this->starterKitNextjsService = $starterkit_nextjs_service; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('state'), - $container->get('module_handler'), - $container->get('link_generator'), - $container->get('info_parser'), - $container->get('entity_type.manager'), - $container->get('acquia_cms_headless.starterkit_nextjs') - ); + $instance = parent::create($container); + $instance->entityTypeManager = $container->get('entity_type.manager'); + $instance->starterKitNextjsService = $container->get('acquia_cms_headless.starterkit_nextjs'); + $instance->headlessRoleLabel = $instance->entityTypeManager->getStorage('user_role')->load('headless')->label(); + + return $instance; } /** diff --git a/modules/acquia_cms_headless/src/Plugin/AcquiaCmsHeadless/HeadlessNextEntityTypes.php b/modules/acquia_cms_headless/src/Plugin/AcquiaCmsHeadless/HeadlessNextEntityTypes.php index 5ab3decdf..e931a6788 100644 --- a/modules/acquia_cms_headless/src/Plugin/AcquiaCmsHeadless/HeadlessNextEntityTypes.php +++ b/modules/acquia_cms_headless/src/Plugin/AcquiaCmsHeadless/HeadlessNextEntityTypes.php @@ -24,34 +24,6 @@ * ) */ class HeadlessNextEntityTypes extends AcquiaCmsDashboardBase { - /** - * The state interface. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; - - - /** - * The module handler. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** - * The link generator. - * - * @var \Drupal\Core\Utility\LinkGeneratorInterface - */ - protected $linkGenerator; - - /** - * The info file parser. - * - * @var \Drupal\Core\Extension\InfoParserInterface - */ - protected $infoParser; /** * The EntityTypeManager service. @@ -74,27 +46,15 @@ class HeadlessNextEntityTypes extends AcquiaCmsDashboardBase { */ protected $module = 'next'; - /** - * {@inheritdoc} - */ - public function __construct(StateInterface $state, ModuleHandlerInterface $module_handler, LinkGeneratorInterface $link_generator, InfoParserInterface $info_parser, EntityTypeManagerInterface $entity_type_manager, StarterkitNextjsService $starterKitNextjsService) { - parent::__construct($state, $module_handler, $link_generator, $info_parser); - $this->entityTypeManager = $entity_type_manager; - $this->starterKitNextjsService = $starterKitNextjsService; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('state'), - $container->get('module_handler'), - $container->get('link_generator'), - $container->get('info_parser'), - $container->get('entity_type.manager'), - $container->get('acquia_cms_headless.starterkit_nextjs') - ); + $instance = parent::create($container); + $instance->entityTypeManager = $container->get('entity_type.manager'); + $instance->starterKitNextjsService = $container->get('acquia_cms_headless.starterkit_nextjs'); + + return $instance; } /** diff --git a/modules/acquia_cms_headless/src/Plugin/AcquiaCmsHeadless/HeadlessNextSites.php b/modules/acquia_cms_headless/src/Plugin/AcquiaCmsHeadless/HeadlessNextSites.php index 9085a23be..8cedd0870 100644 --- a/modules/acquia_cms_headless/src/Plugin/AcquiaCmsHeadless/HeadlessNextSites.php +++ b/modules/acquia_cms_headless/src/Plugin/AcquiaCmsHeadless/HeadlessNextSites.php @@ -26,41 +26,6 @@ * ) */ class HeadlessNextSites extends AcquiaCmsDashboardBase { - /** - * The state interface. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; - - - /** - * The module handler. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** - * The link generator. - * - * @var \Drupal\Core\Utility\LinkGeneratorInterface - */ - protected $linkGenerator; - - /** - * The info file parser. - * - * @var \Drupal\Core\Extension\InfoParserInterface - */ - protected $infoParser; - - /** - * Provides the database connection. - * - * @var \Drupal\Core\Database\Connection - */ - protected $connection; /** * The EntityTypeManager service. @@ -83,29 +48,15 @@ class HeadlessNextSites extends AcquiaCmsDashboardBase { */ protected $module = 'next'; - /** - * {@inheritdoc} - */ - public function __construct(StateInterface $state, ModuleHandlerInterface $module_handler, LinkGeneratorInterface $link_generator, InfoParserInterface $info_parser, Connection $connection, EntityTypeManagerInterface $entity_type_manager, StarterkitNextjsService $starterKitNextjsService) { - parent::__construct($state, $module_handler, $link_generator, $info_parser); - $this->connection = $connection; - $this->entityTypeManager = $entity_type_manager; - $this->starterKitNextjsService = $starterKitNextjsService; - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('state'), - $container->get('module_handler'), - $container->get('link_generator'), - $container->get('info_parser'), - $container->get('database'), - $container->get('entity_type.manager'), - $container->get('acquia_cms_headless.starterkit_nextjs') - ); + $instance = parent::create($container); + $instance->entityTypeManager = $container->get('entity_type.manager'); + $instance->starterKitNextjsService = $container->get('acquia_cms_headless.starterkit_nextjs'); + + return $instance; } /**