From af4b128c0d28a6c1147a42587559ee50a0d099a3 Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Wed, 27 Nov 2024 13:36:00 +0530 Subject: [PATCH 01/27] ACMS-4329: Update PHP version to 8.3 for acquia pipeline. --- acquia-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acquia-pipelines.yml b/acquia-pipelines.yml index 5e065c520..eb4063182 100644 --- a/acquia-pipelines.yml +++ b/acquia-pipelines.yml @@ -5,7 +5,7 @@ services: - composer: version: 2 - php: - version: 8.1 + version: 8.3 events: build: From f16d84c6a8360d82ff53845897632f7f0ab9ab70 Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Fri, 29 Nov 2024 18:35:49 +0530 Subject: [PATCH 02/27] ACMS-4329: New CD workflow added. --- .github/cd.gitignore | 11 ++ .github/workflows/deployment.workflow.yml | 142 ++++++++++++++++++++++ composer.json | 17 +-- composer.lock | 82 +++++++++---- 4 files changed, 216 insertions(+), 36 deletions(-) create mode 100644 .github/cd.gitignore create mode 100644 .github/workflows/deployment.workflow.yml diff --git a/.github/cd.gitignore b/.github/cd.gitignore new file mode 100644 index 000000000..44d8613c7 --- /dev/null +++ b/.github/cd.gitignore @@ -0,0 +1,11 @@ +/docroot/sites/*/settings.*.php +/docroot/sites/*/services*.yml +/docroot/sites/*/files +/docroot/sites/*/private +/docroot/sites/simpletest + +# Directories specific to this template +/docroot/libraries +/docroot/modules/contrib +/docroot/profiles/contrib +/docroot/themes/contrib diff --git a/.github/workflows/deployment.workflow.yml b/.github/workflows/deployment.workflow.yml new file mode 100644 index 000000000..6faa617c2 --- /dev/null +++ b/.github/workflows/deployment.workflow.yml @@ -0,0 +1,142 @@ +name: "Code Deployment on Acquia Environment" +on: + push: + branches: [ develop, main ] +jobs: + acquia_code_deployment: + if: ${{ github.event_name == 'push' }} + name: "Code Deployment on Acquia Environment" + env: + GIT_AUTHOR_NAME: "Vishal Khode" + GIT_COMMITTER_NAME: "Vishal Khode" + GIT_COMMITTER_EMAIL: "vishal.khode@acquia.com" + GIT_AUTHOR_EMAIL: "vishal.khode@acquia.com" + runs-on: ubuntu-latest + environment: acquia_code_deployment + concurrency: production + steps: + - uses: actions/checkout@v4 + - uses: shivammathur/setup-php@v2 + with: + php-version: 8.3 + - name: Configure SSH keys + run: | + mkdir -p ~/.ssh + echo "${ACQUIA_CLOUD_SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + eval `ssh-agent -s` + ssh-add ~/.ssh/id_rsa + + # Loop through each line in the environment variable. + echo "${ACQUIA_CLOUD_KNOWN_HOSTS}" | while IFS= read -r KNOWN_HOST; do + if [[ -n "${KNOWN_HOST}" ]]; then + CLEANED_HOST=$(echo "${KNOWN_HOST}" | tr -d '\r' | xargs -n1) + ssh-keyscan "${CLEANED_HOST}" >> ~/.ssh/known_hosts 2>/dev/null || { + echo "Warning: Unable to scan host ${CLEANED_HOST}. Skipping." + } + fi + done + shell: bash + env: + ACQUIA_CLOUD_SSH_PRIVATE_KEY: ${{ secrets.ACQUIA_CLOUD_SSH_PRIVATE_KEY }} + ACQUIA_CLOUD_KNOWN_HOSTS: ${{ vars.ACQUIA_CLOUD_KNOWN_HOSTS }} + - name: Setup Drupal Project + run: | + # Install specific version of Drupal Core. + composer require drupal/core:${CORE_VERSION} drupal/core-composer-scaffold:${CORE_VERSION} drupal/core-recommended:${CORE_VERSION} --no-install --no-update -n + + # Move some of development dependencies to production depencies or else acli push:artifact will fail. + composer require oomphinc/composer-installers-extender --no-install --no-update -n + composer update "drupal/core-*" drush/drush "drupal/*" -W --with=drupal/core:${CORE_VERSION} --minimal-changes + + # Include MySQL 5.7 connection settings, before DRS require line is added. + echo "require DRUPAL_ROOT . '/modules/contrib/mysql57/settings.inc';" >> docroot/sites/default/settings.php + + # Download acquia/drupal-recommended-settings plugin & drupal/mysql57 library. + composer require acquia/drupal-recommended-settings:^1.1 drupal/mysql57 + + # Update .gitignore file, otherwise acli won't push any settings file. + sed -i 's/docroot\//docroot\/core/' .gitignore + cat .github/cd.gitignore >> .gitignore 2>/dev/null + + # Create symlink directory for multisite headless and community. + cd docroot/sites + ln -s default headless + ln -s default community + cd - + git add . && git commit -m "Update drupal core and it's dependencies." + env: + CORE_VERSION: ^11 + - name: Setup Acquia CLI + run: | + curl -OL https://github.com/acquia/cli/releases/latest/download/acli.phar + chmod +x acli.phar + mv acli.phar /usr/local/bin/acli + acli --version + + acli auth:login --key=${ACQUIA_CLOUD_API_KEY} --secret=${ACQUIA_CLOUD_API_SECRET} -n + acli link ${ACQUIA_APPLICATION_UUID} -n + acli remote:aliases:download -n + git add . && git commit -m "Added acli & drush alias configurations." + env: + ACQUIA_CLOUD_API_KEY: ${{ secrets.ACQUIA_CLOUD_API_KEY }} + ACQUIA_CLOUD_API_SECRET: ${{ secrets.ACQUIA_CLOUD_API_SECRET }} + ACQUIA_APPLICATION_UUID: ${{ secrets.ACQUIA_APPLICATION_UUID }} + - name: Deploy & Switch Code + shell: bash + run: | + BRANCH_TO_DEPLOY=acli-${GITHUB_REF_NAME} + + acli push:artifact ${ACQUIA_CLOUD_ENVIRONMENT} --destination-git-branch=${BRANCH_TO_DEPLOY} -n + + DEPLOYED_BRANCH=$(acli api:environments:find ${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.vcs.path') + + # If BRANCH_TO_DEPLOY is NOT the same as DEPLOYED_BRANCH. Then switch code. + if [ "$BRANCH_TO_DEPLOY" != "$DEPLOYED_BRANCH" ]; then + # Step 1: Run the code:switch command and capture its output. + response=$(acli api:environments:code-switch ${ACQUIA_CLOUD_ENVIRONMENT} ${BRANCH_TO_DEPLOY} -n) + + # Step 2: Extract the notification ID from the JSON response + notification_id=$(echo "$response" | jq -r '.notification') + + # Step 3: Check if the notification ID was successfully extracted. + if [[ -z "$notification_id" ]]; then + echo "Error: Notification ID not found in the response." + exit 1 + fi + + progress=0 + timeout=1800 # Timeout in seconds (30 minutes). + start_time=$(date +%s) # Get the current time in seconds + + echo "Please wait while code is being switched..." + # Step 4: Poll the notification status until progress reaches 100. + while [[ "$progress" -lt 100 ]]; do + # Run the notification find command. + notification_response=$(acli api:notifications:find "$notification_id" -n) + + # Extract the progress value. + progress=$(echo "$notification_response" | jq -r '.progress') + + # Display current progress. + #echo "Current progress: $progress%" + + # Check if we've exceeded the timeout (5 minutes). + current_time=$(date +%s) + elapsed_time=$((current_time - start_time)) + + if [[ "$elapsed_time" -ge "$timeout" ]]; then + # Calculate minutes and seconds. + minutes=$((elapsed_time / 60)) + seconds=$((elapsed_time % 60)) + + echo "Error: Timeout reached after $minutes minute(s) and $seconds second(s). Progress did not reach 100%." + exit 1 + fi + + # Wait for 5 seconds before polling again. + sleep 5 + done + fi + env: + ACQUIA_CLOUD_ENVIRONMENT: ${{ secrets.ACQUIA_CLOUD_ENVIRONMENT }} diff --git a/composer.json b/composer.json index da7f4231b..dd70c2e6d 100644 --- a/composer.json +++ b/composer.json @@ -223,14 +223,6 @@ } } }, - "consumer_image_styles": { - "type": "vcs", - "url": "https://git.drupalcode.org/issue/consumer_image_styles-3429496.git" - }, - "config_filter": { - "type": "vcs", - "url": "https://git.drupalcode.org/issue/config_filter-3428542.git" - }, "drupal": { "type": "composer", "url": "https://packages.drupal.org/8" @@ -262,8 +254,7 @@ "phpstan/extension-installer": true, "tbachert/spi": true, "webdriver-binary/binary-chromedriver": true, - "wikimedia/composer-merge-plugin": true, - "tbachert/spi": true + "wikimedia/composer-merge-plugin": true }, "preferred-install": { "drupal/core": "dist" @@ -287,8 +278,10 @@ "[web-root]/profiles/README.txt": false, "[web-root]/robots.txt": false, "[web-root]/sites/README.txt": false, - "[web-root]/sites/default/default.settings.php": { - "append": "./patches/d9-acms-settings.patch" + "[web-root]/sites/default/settings.php": { + "mode": "replace", + "overwrite": false, + "path": "docroot/core/assets/scaffold/files/default.settings.php" }, "[web-root]/themes/README.txt": false, "[web-root]/themes/contrib/cohesion-theme/templates/maintenance-page.html.twig": "./patches/maintenance-page.patch", diff --git a/composer.lock b/composer.lock index 3247153fd..11c249435 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "159f1bf0ea74b93f8d8588e5eec5bdcf", + "content-hash": "f7f9e623cf8da30e566ee0d0052fb980", "packages": [ { "name": "acquia/acquia-cms-starterkit", @@ -2390,7 +2390,7 @@ "dist": { "type": "path", "url": "./modules/acquia_cms_common", - "reference": "36ebfe06447b4f28301a18995d197336fb6ce1f3" + "reference": "b2fe6b5717ef5c06a9a978b712bb12252d309a4f" }, "require": { "acquia/drupal-environment-detector": "^1.5", @@ -4010,28 +4010,61 @@ }, { "name": "drupal/consumer_image_styles", - "version": "4.0.8", + "version": "4.0.10", "source": { "type": "git", - "url": "https://git.drupalcode.org/issue/consumer_image_styles-3429496.git", - "reference": "89263183da961c033eb05eb86c2f727df21de7ff" + "url": "https://git.drupalcode.org/project/consumer_image_styles.git", + "reference": "4.0.10" + }, + "dist": { + "type": "zip", + "url": "https://ftp.drupal.org/files/projects/consumer_image_styles-4.0.10.zip", + "reference": "4.0.10", + "shasum": "6894d5bde15984a4597e19e6ebab46f464a15b10" }, "require": { - "drupal/consumers": "^1.15", - "drupal/jsonapi_extras": "^3.23" + "drupal/consumers": "^1.19", + "drupal/core": "^9.5 || ^10 || ^11", + "php": ">=8.0" + }, + "require-dev": { + "drupal/jsonapi_extras": "^3.26" }, "type": "drupal-module", + "extra": { + "drupal": { + "version": "4.0.10", + "datestamp": "1729009525", + "security-coverage": { + "status": "covered", + "message": "Covered by Drupal's security advisory policy" + } + } + }, + "notification-url": "https://packages.drupal.org/8/downloads", "license": [ "GPL-2.0-or-later" ], "authors": [ { "name": "Mateu Aguiló Bosch", + "homepage": "https://www.drupal.org/user/405824", "email": "mateu.aguilo.bosch@gmail.com" + }, + { + "name": "e0ipso", + "homepage": "https://www.drupal.org/user/550110" + }, + { + "name": "japerry", + "homepage": "https://www.drupal.org/user/45640" } ], "description": "Consumer Image Styles integrates with JSON API to provide image styles to your images in your decoupled project.", - "time": "2022-12-09T06:06:46+00:00" + "homepage": "https://www.drupal.org/project/consumer_image_styles", + "support": { + "source": "https://git.drupalcode.org/project/consumer_image_styles" + } }, { "name": "drupal/consumers", @@ -13912,26 +13945,27 @@ }, { "name": "symfony/http-client", - "version": "v7.1.5", + "version": "v7.2.0", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "abca35865118edf35a23f2f24978a1784c831cb4" + "reference": "955e43336aff03df1e8a8e17daefabb0127a313b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/abca35865118edf35a23f2f24978a1784c831cb4", - "reference": "abca35865118edf35a23f2f24978a1784c831cb4", + "url": "https://api.github.com/repos/symfony/http-client/zipball/955e43336aff03df1e8a8e17daefabb0127a313b", + "reference": "955e43336aff03df1e8a8e17daefabb0127a313b", "shasum": "" }, "require": { "php": ">=8.2", "psr/log": "^1|^2|^3", "symfony/deprecation-contracts": "^2.5|^3", - "symfony/http-client-contracts": "^3.4.1", + "symfony/http-client-contracts": "~3.4.3|^3.5.1", "symfony/service-contracts": "^2.5|^3" }, "conflict": { + "amphp/amp": "<2.5", "php-http/discovery": "<1.15", "symfony/http-foundation": "<6.4" }, @@ -13942,14 +13976,14 @@ "symfony/http-client-implementation": "3.0" }, "require-dev": { - "amphp/amp": "^2.5", - "amphp/http-client": "^4.2.1", - "amphp/http-tunnel": "^1.0", + "amphp/http-client": "^4.2.1|^5.0", + "amphp/http-tunnel": "^1.0|^2.0", "amphp/socket": "^1.1", "guzzlehttp/promises": "^1.4|^2.0", "nyholm/psr7": "^1.0", "php-http/httplug": "^1.0|^2.0", "psr/http-client": "^1.0", + "symfony/amphp-http-client-meta": "^1.0|^2.0", "symfony/dependency-injection": "^6.4|^7.0", "symfony/http-kernel": "^6.4|^7.0", "symfony/messenger": "^6.4|^7.0", @@ -13986,7 +14020,7 @@ "http" ], "support": { - "source": "https://github.com/symfony/http-client/tree/v7.1.5" + "source": "https://github.com/symfony/http-client/tree/v7.2.0" }, "funding": [ { @@ -14002,20 +14036,20 @@ "type": "tidelift" } ], - "time": "2024-09-20T13:35:23+00:00" + "time": "2024-11-29T08:22:02+00:00" }, { "name": "symfony/http-client-contracts", - "version": "v3.5.0", + "version": "v3.5.1", "source": { "type": "git", "url": "https://github.com/symfony/http-client-contracts.git", - "reference": "20414d96f391677bf80078aa55baece78b82647d" + "reference": "c2f3ad828596624ca39ea40f83617ef51ca8bbf9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/20414d96f391677bf80078aa55baece78b82647d", - "reference": "20414d96f391677bf80078aa55baece78b82647d", + "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/c2f3ad828596624ca39ea40f83617ef51ca8bbf9", + "reference": "c2f3ad828596624ca39ea40f83617ef51ca8bbf9", "shasum": "" }, "require": { @@ -14064,7 +14098,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/http-client-contracts/tree/v3.5.0" + "source": "https://github.com/symfony/http-client-contracts/tree/v3.5.1" }, "funding": [ { @@ -14080,7 +14114,7 @@ "type": "tidelift" } ], - "time": "2024-04-18T09:32:20+00:00" + "time": "2024-11-25T12:02:18+00:00" }, { "name": "symfony/http-foundation", From eb859684cc2605c2e89a333cdec36c195a4a8699 Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Tue, 3 Dec 2024 18:26:29 +0530 Subject: [PATCH 03/27] ACMS-4329: Temp commit to fix CI issue. --- .github/workflows/acquia_cms_ci.workflow.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/acquia_cms_ci.workflow.yml b/.github/workflows/acquia_cms_ci.workflow.yml index a17943db9..cde428f6c 100644 --- a/.github/workflows/acquia_cms_ci.workflow.yml +++ b/.github/workflows/acquia_cms_ci.workflow.yml @@ -9,6 +9,8 @@ on: paths-ignore: - README.md +env: + ORCA_VERSION: ^4 jobs: static_code_analysis: if: ${{ github.event_name == 'pull_request' }} @@ -17,7 +19,6 @@ jobs: # Provide your package's name. ORCA_SUT_NAME: acquia/acquia_cms ORCA_SUT_BRANCH: develop - ORCA_VERSION: ^4 ORCA_PACKAGES_CONFIG_ALTER: ../acquia_cms/tests/packages_alter.yml ORCA_FIXTURE_PROJECT_TEMPLATE: acquia/drupal-recommended-project ORCA_ENABLE_NIGHTWATCH: "FALSE" @@ -151,6 +152,7 @@ jobs: composer create-project --no-dev --ignore-platform-req=php acquia/orca ../orca "$ORCA_VERSION" -n curl https://gist.githubusercontent.com/rajeshreeputra/170586f217b422eb9cdfd9ca9457a2e3/raw/c2f277ba9005b91d7f662cacf37b3940a66a9b8c/sut-path-reposories.patch | git -C ../orca apply curl https://gist.githubusercontent.com/rajeshreeputra/efe6fd50fc839e0e05480a5eb58d1ba4/raw/c5e81aa3c0fba9f4abe42460f3d24c7ca976a527/remove-local-settings.patch | git -C ../orca apply + composer config extra."drupal-scaffold".file-mapping {} --json -d ${ORCA_SUT_DIR} # - name: Configure AWS Credentials # uses: aws-actions/configure-aws-credentials@v1 # with: @@ -255,6 +257,7 @@ jobs: composer self-update composer create-project --no-dev --ignore-platform-req=php acquia/orca ../orca "$ORCA_VERSION" -n curl https://gist.githubusercontent.com/rajeshreeputra/170586f217b422eb9cdfd9ca9457a2e3/raw/c2f277ba9005b91d7f662cacf37b3940a66a9b8c/sut-path-reposories.patch | git -C ../orca apply + composer config extra."drupal-scaffold".file-mapping {} --json -d ${ORCA_SUT_DIR} - name: Before Install run: | # Remove all ExistingSite test in CI. @@ -346,6 +349,7 @@ jobs: composer self-update composer create-project --no-dev --ignore-platform-req=php acquia/orca ../orca "$ORCA_VERSION" -n curl https://gist.githubusercontent.com/rajeshreeputra/170586f217b422eb9cdfd9ca9457a2e3/raw/c2f277ba9005b91d7f662cacf37b3940a66a9b8c/sut-path-reposories.patch | git -C ../orca apply + composer config extra."drupal-scaffold".file-mapping {} --json -d ${ORCA_SUT_DIR} - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1 with: From ac4202235c5df25c3fac57282e69ec17056d0928 Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Tue, 3 Dec 2024 01:33:37 +0530 Subject: [PATCH 04/27] ACMS-4239: Temp commit. --- .github/workflows/deployment.workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deployment.workflow.yml b/.github/workflows/deployment.workflow.yml index 6faa617c2..bf84f941a 100644 --- a/.github/workflows/deployment.workflow.yml +++ b/.github/workflows/deployment.workflow.yml @@ -1,7 +1,7 @@ name: "Code Deployment on Acquia Environment" on: push: - branches: [ develop, main ] + branches: [ develop, main, ACMS-4329 ] jobs: acquia_code_deployment: if: ${{ github.event_name == 'push' }} From f9859bcee76b296bdf8a0f594196a78442597cf3 Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Wed, 4 Dec 2024 16:01:27 +0530 Subject: [PATCH 05/27] ACMS-4329: Remove Acquia Pipelines CD. --- acquia-pipelines.yml | 47 -------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 acquia-pipelines.yml diff --git a/acquia-pipelines.yml b/acquia-pipelines.yml deleted file mode 100644 index eb4063182..000000000 --- a/acquia-pipelines.yml +++ /dev/null @@ -1,47 +0,0 @@ -# This file is used by Acquia Pipelines continuous integration. Upon success, an -# artifact is deployed to the `orionacms` subscription on Acquia Cloud. -version: 1.3.0 -services: - - composer: - version: 2 - - php: - version: 8.3 - -events: - build: - steps: - - setup: - type: script - script: - - composer validate --no-check-all --ansi --no-interaction - - composer install - - mkdir -p docroot/modules/acquia_cms - # Create symlink directory for multisite headless and community. - - cd docroot/sites - - ln -s default headless - - ln -s default community - - cd - - - composer archive --format zip --file acquia_cms - - unzip acquia_cms.zip -d docroot/modules/acquia_cms - # Commenting as it's no longer needed and this is failing deployment. - # - front-end: - # type: script - # script: - # - cd docroot/themes/contrib/acquia_claro - # - npm install - # - npm run build - # - cd - - - cleanup: - type: script - script: - - rm acquia_cms.zip - # Prepare settings.php with the minimum required for Cloud. - - chmod -R +w docroot/sites/default - - cp docroot/sites/default/default.settings.php docroot/sites/default/settings.php - # Clear any config directories that Cloud tries to set in the include file. - - echo "\$config_directories = [];" >> docroot/sites/default/settings.php - # Use the existing `config` directory we already have. Cloud gets confused - # because we already have a config directory above docroot and manipulating it - # in Pipelines doesn't seem to work. This deployment is ephemeral, so using - # the existing config directory isn't a problem. - - echo "\$config_directories['sync'] = '../config';" >> docroot/sites/default/settings.php From e0acf49145747bae9467551b5eb8f94d9eb063d4 Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Wed, 4 Dec 2024 16:01:44 +0530 Subject: [PATCH 06/27] ACMS-4329: Minor improvements made. --- .github/workflows/deployment.workflow.yml | 48 +++++++++++++---------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/.github/workflows/deployment.workflow.yml b/.github/workflows/deployment.workflow.yml index bf84f941a..f9e4acf8e 100644 --- a/.github/workflows/deployment.workflow.yml +++ b/.github/workflows/deployment.workflow.yml @@ -2,23 +2,35 @@ name: "Code Deployment on Acquia Environment" on: push: branches: [ develop, main, ACMS-4329 ] + +concurrency: + group: "ci-${{ github.ref }}" + cancel-in-progress: true + +env: + GIT_AUTHOR_NAME: "CD" + GIT_COMMITTER_NAME: "CD" + GIT_COMMITTER_EMAIL: "no-reply@acquia.com" + GIT_AUTHOR_EMAIL: "no-reply@acquia.com" + PHP_VERSION: 8.3 + CORE_VERSION: ^11 + jobs: acquia_code_deployment: if: ${{ github.event_name == 'push' }} - name: "Code Deployment on Acquia Environment" - env: - GIT_AUTHOR_NAME: "Vishal Khode" - GIT_COMMITTER_NAME: "Vishal Khode" - GIT_COMMITTER_EMAIL: "vishal.khode@acquia.com" - GIT_AUTHOR_EMAIL: "vishal.khode@acquia.com" + name: "Code Deployment" runs-on: ubuntu-latest environment: acquia_code_deployment - concurrency: production + env: + ACQUIA_CLOUD_ENVIRONMENT: "dev" + ACQUIA_CLOUD_API_KEY: ${{ secrets.ACQUIA_CLOUD_API_KEY }} + ACQUIA_CLOUD_API_SECRET: ${{ secrets.ACQUIA_CLOUD_API_SECRET }} + ACQUIA_CLOUD_APPLICATION: ${{ secrets.ACQUIA_CLOUD_APPLICATION }} steps: - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: - php-version: 8.3 + php-version: ${{ env.PHP_VERSION }} - name: Configure SSH keys run: | mkdir -p ~/.ssh @@ -64,9 +76,7 @@ jobs: ln -s default headless ln -s default community cd - - git add . && git commit -m "Update drupal core and it's dependencies." - env: - CORE_VERSION: ^11 + git add . && git commit -m "Update drupal core and it's dependencies." 2>/dev/null - name: Setup Acquia CLI run: | curl -OL https://github.com/acquia/cli/releases/latest/download/acli.phar @@ -75,26 +85,24 @@ jobs: acli --version acli auth:login --key=${ACQUIA_CLOUD_API_KEY} --secret=${ACQUIA_CLOUD_API_SECRET} -n + ACQUIA_APPLICATION_UUID=$(acli api:applications:find ${ACQUIA_CLOUD_APPLICATION} -n | jq -r '.uuid') acli link ${ACQUIA_APPLICATION_UUID} -n + acli remote:aliases:download -n - git add . && git commit -m "Added acli & drush alias configurations." - env: - ACQUIA_CLOUD_API_KEY: ${{ secrets.ACQUIA_CLOUD_API_KEY }} - ACQUIA_CLOUD_API_SECRET: ${{ secrets.ACQUIA_CLOUD_API_SECRET }} - ACQUIA_APPLICATION_UUID: ${{ secrets.ACQUIA_APPLICATION_UUID }} + git add . && git commit -m "Added acli & drush alias configurations." 2>/dev/null - name: Deploy & Switch Code shell: bash run: | BRANCH_TO_DEPLOY=acli-${GITHUB_REF_NAME} - acli push:artifact ${ACQUIA_CLOUD_ENVIRONMENT} --destination-git-branch=${BRANCH_TO_DEPLOY} -n + acli push:artifact ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} --destination-git-branch=${BRANCH_TO_DEPLOY} -n - DEPLOYED_BRANCH=$(acli api:environments:find ${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.vcs.path') + DEPLOYED_BRANCH=$(acli api:environments:find ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.vcs.path') # If BRANCH_TO_DEPLOY is NOT the same as DEPLOYED_BRANCH. Then switch code. if [ "$BRANCH_TO_DEPLOY" != "$DEPLOYED_BRANCH" ]; then # Step 1: Run the code:switch command and capture its output. - response=$(acli api:environments:code-switch ${ACQUIA_CLOUD_ENVIRONMENT} ${BRANCH_TO_DEPLOY} -n) + response=$(acli api:environments:code-switch ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} ${BRANCH_TO_DEPLOY} -n) # Step 2: Extract the notification ID from the JSON response notification_id=$(echo "$response" | jq -r '.notification') @@ -138,5 +146,3 @@ jobs: sleep 5 done fi - env: - ACQUIA_CLOUD_ENVIRONMENT: ${{ secrets.ACQUIA_CLOUD_ENVIRONMENT }} From dcdfc3492cd8992c64cf59b0811b5e5d130a49b8 Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Wed, 4 Dec 2024 17:58:45 +0530 Subject: [PATCH 07/27] Revert "ACMS-4239: Temp commit." This reverts commit ac4202235c5df25c3fac57282e69ec17056d0928. --- .github/workflows/deployment.workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deployment.workflow.yml b/.github/workflows/deployment.workflow.yml index f9e4acf8e..b8d5fb678 100644 --- a/.github/workflows/deployment.workflow.yml +++ b/.github/workflows/deployment.workflow.yml @@ -1,7 +1,7 @@ name: "Code Deployment on Acquia Environment" on: push: - branches: [ develop, main, ACMS-4329 ] + branches: [ develop ] concurrency: group: "ci-${{ github.ref }}" From 66487934fa0abce9868c6b34aa35e26b920f5808 Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Wed, 4 Dec 2024 19:08:39 +0530 Subject: [PATCH 08/27] ACMS-4329: Add manual deployment workflow. --- .github/workflows/deployment.workflow.yml | 30 ++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deployment.workflow.yml b/.github/workflows/deployment.workflow.yml index b8d5fb678..592bfd8e2 100644 --- a/.github/workflows/deployment.workflow.yml +++ b/.github/workflows/deployment.workflow.yml @@ -2,6 +2,30 @@ name: "Code Deployment on Acquia Environment" on: push: branches: [ develop ] + workflow_dispatch: + inputs: + environment: + description: 'Choose environment' + type: choice + options: + - dev + - stage + - prod + - next + - ode1 + - ode2 + - ode3 + - ode4 + - ode5 + - ode6 + - ode7 + - ode8 + required: true + default: 'dev' + drupal-core: + description: 'Choose Drupal Core' + required: true + default: '^11' concurrency: group: "ci-${{ github.ref }}" @@ -13,16 +37,16 @@ env: GIT_COMMITTER_EMAIL: "no-reply@acquia.com" GIT_AUTHOR_EMAIL: "no-reply@acquia.com" PHP_VERSION: 8.3 - CORE_VERSION: ^11 + CORE_VERSION: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.drupal-core || '^11' }} + ACQUIA_CLOUD_ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'dev' }} jobs: acquia_code_deployment: - if: ${{ github.event_name == 'push' }} + if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }} name: "Code Deployment" runs-on: ubuntu-latest environment: acquia_code_deployment env: - ACQUIA_CLOUD_ENVIRONMENT: "dev" ACQUIA_CLOUD_API_KEY: ${{ secrets.ACQUIA_CLOUD_API_KEY }} ACQUIA_CLOUD_API_SECRET: ${{ secrets.ACQUIA_CLOUD_API_SECRET }} ACQUIA_CLOUD_APPLICATION: ${{ secrets.ACQUIA_CLOUD_APPLICATION }} From 9aa939a29caa4260817ee26f6d8473e09534d007 Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Wed, 4 Dec 2024 19:10:09 +0530 Subject: [PATCH 09/27] Minor debug. --- .github/workflows/deployment.workflow.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deployment.workflow.yml b/.github/workflows/deployment.workflow.yml index 592bfd8e2..a7d9cdc5e 100644 --- a/.github/workflows/deployment.workflow.yml +++ b/.github/workflows/deployment.workflow.yml @@ -26,6 +26,16 @@ on: description: 'Choose Drupal Core' required: true default: '^11' + php-version: + description: 'Choose PHP Version' + type: choice + options: + - "8.1" + - "8.2" + - "8.3" + - "8.4" + required: true + default: '8.3' concurrency: group: "ci-${{ github.ref }}" @@ -36,7 +46,7 @@ env: GIT_COMMITTER_NAME: "CD" GIT_COMMITTER_EMAIL: "no-reply@acquia.com" GIT_AUTHOR_EMAIL: "no-reply@acquia.com" - PHP_VERSION: 8.3 + PHP_VERSION: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.php-version || '8.3' }} CORE_VERSION: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.drupal-core || '^11' }} ACQUIA_CLOUD_ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'dev' }} @@ -114,6 +124,16 @@ jobs: acli remote:aliases:download -n git add . && git commit -m "Added acli & drush alias configurations." 2>/dev/null + - name: Find & Switch PHP Version + run: | + # Find the PHP version. + ENV_PHP_VERSION=$(acli api:environments:find ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.configuration.php.version') + echo $ENV_PHP_VERSION + exit 1 + # If PHP_VERSION is NOT the same as the one we want to switch to. Then switch PHP version. + if [ "${ENV_PHP_VERSION}" != "${PHP_VERSION}" ]; then + acli api:environments:update ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} --lang_version=${PHP_VERSION} -n + fi - name: Deploy & Switch Code shell: bash run: | From ea08e4b5255e3befb29828650087156b90eef78a Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Wed, 4 Dec 2024 23:18:21 +0530 Subject: [PATCH 10/27] ACMS-4329: Temp run github CI. --- .github/workflows/deployment.workflow.yml | 41 +++++++++++++++++------ 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/.github/workflows/deployment.workflow.yml b/.github/workflows/deployment.workflow.yml index a7d9cdc5e..b8d3926bf 100644 --- a/.github/workflows/deployment.workflow.yml +++ b/.github/workflows/deployment.workflow.yml @@ -1,7 +1,7 @@ -name: "Code Deployment on Acquia Environment" +name: "Code Deployment (Acquia)" on: push: - branches: [ develop ] + branches: [ develop, ACMS-4329 ] workflow_dispatch: inputs: environment: @@ -23,7 +23,7 @@ on: required: true default: 'dev' drupal-core: - description: 'Choose Drupal Core' + description: 'Choose Drupal Core Version' required: true default: '^11' php-version: @@ -36,6 +36,10 @@ on: - "8.4" required: true default: '8.3' + download-latest-dependencies: + description: 'Download latest dependencies' + type: boolean + default: false concurrency: group: "ci-${{ github.ref }}" @@ -47,8 +51,9 @@ env: GIT_COMMITTER_EMAIL: "no-reply@acquia.com" GIT_AUTHOR_EMAIL: "no-reply@acquia.com" PHP_VERSION: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.php-version || '8.3' }} - CORE_VERSION: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.drupal-core || '^11' }} + CORE_VERSION: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.drupal-core || '' }} ACQUIA_CLOUD_ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'dev' }} + DOWNLOAD_LATEST_DEPENDENCIES: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.download-latest-dependencies || 'false' }} jobs: acquia_code_deployment: @@ -88,12 +93,24 @@ jobs: ACQUIA_CLOUD_KNOWN_HOSTS: ${{ vars.ACQUIA_CLOUD_KNOWN_HOSTS }} - name: Setup Drupal Project run: | - # Install specific version of Drupal Core. - composer require drupal/core:${CORE_VERSION} drupal/core-composer-scaffold:${CORE_VERSION} drupal/core-recommended:${CORE_VERSION} --no-install --no-update -n + # Download specific version of Drupal Core, if requested. + [ -n "${CORE_VERSION}" ] && echo composer require drupal/core:${CORE_VERSION} drupal/core-composer-scaffold:${CORE_VERSION} drupal/core-recommended:${CORE_VERSION} --no-install --no-update -n || true - # Move some of development dependencies to production depencies or else acli push:artifact will fail. + # Move some of development dependencies to production dependencies or else acli push:artifact will fail. composer require oomphinc/composer-installers-extender --no-install --no-update -n - composer update "drupal/core-*" drush/drush "drupal/*" -W --with=drupal/core:${CORE_VERSION} --minimal-changes + + if [ "${DOWNLOAD_LATEST_DEPENDENCIES}" == "true" ]; then + rm composer.lock + composer install + else + # Update specific version of Drupal Core, if requested or else simply install all dependencies. + if [ -n "${CORE_VERSION}" ]; then + composer update "drupal/core-*" drush/drush "drupal/*" -W --with=drupal/core:${CORE_VERSION} --minimal-changes + else + # In CI, we don't need to run composer install again, as it's already will be done by below command. + composer update oomphinc/composer-installers-extender + fi + fi # Include MySQL 5.7 connection settings, before DRS require line is added. echo "require DRUPAL_ROOT . '/modules/contrib/mysql57/settings.inc';" >> docroot/sites/default/settings.php @@ -128,11 +145,13 @@ jobs: run: | # Find the PHP version. ENV_PHP_VERSION=$(acli api:environments:find ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.configuration.php.version') - echo $ENV_PHP_VERSION - exit 1 + echo "The CI php-version: ${PHP_VERSION}" + echo "The Acquia Cloud environment php-version: $ENV_PHP_VERSION" # If PHP_VERSION is NOT the same as the one we want to switch to. Then switch PHP version. if [ "${ENV_PHP_VERSION}" != "${PHP_VERSION}" ]; then - acli api:environments:update ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} --lang_version=${PHP_VERSION} -n + echo "Switching PHP version to ${PHP_VERSION}" + acli api:environments:update ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} --lang_version=${PHP_VERSION} -n + sleep 10 fi - name: Deploy & Switch Code shell: bash From e7d9bd84349d9b267846d75f5263d6d538e8a835 Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Thu, 5 Dec 2024 01:00:31 +0530 Subject: [PATCH 11/27] ACMS-4329: More improvements. --- .github/workflows/deployment.workflow.yml | 81 ++++++++++++----------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/.github/workflows/deployment.workflow.yml b/.github/workflows/deployment.workflow.yml index b8d3926bf..e41fb30ef 100644 --- a/.github/workflows/deployment.workflow.yml +++ b/.github/workflows/deployment.workflow.yml @@ -1,7 +1,7 @@ name: "Code Deployment (Acquia)" on: push: - branches: [ develop, ACMS-4329 ] + branches: [ develop, main, ACMS-*, feature/* ] workflow_dispatch: inputs: environment: @@ -158,54 +158,59 @@ jobs: run: | BRANCH_TO_DEPLOY=acli-${GITHUB_REF_NAME} + # Push changes on Acuia Cloud. acli push:artifact ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} --destination-git-branch=${BRANCH_TO_DEPLOY} -n - DEPLOYED_BRANCH=$(acli api:environments:find ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.vcs.path') + # If the event is push and branch is develop or if CI is triggered manually, then only switch code. + if [[ "${GITHUB_EVENT_NAME}" == "push" && "${GITHUB_REF_NAME}" == "develop" ]] || [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then - # If BRANCH_TO_DEPLOY is NOT the same as DEPLOYED_BRANCH. Then switch code. - if [ "$BRANCH_TO_DEPLOY" != "$DEPLOYED_BRANCH" ]; then - # Step 1: Run the code:switch command and capture its output. - response=$(acli api:environments:code-switch ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} ${BRANCH_TO_DEPLOY} -n) + DEPLOYED_BRANCH=$(acli api:environments:find ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.vcs.path') - # Step 2: Extract the notification ID from the JSON response - notification_id=$(echo "$response" | jq -r '.notification') + # If BRANCH_TO_DEPLOY is NOT the same as DEPLOYED_BRANCH. Then switch code. + if [ "${BRANCH_TO_DEPLOY}" != "${DEPLOYED_BRANCH}" ]; then + # Step 1: Run the code:switch command and capture its output. + response=$(acli api:environments:code-switch ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} ${BRANCH_TO_DEPLOY} -n) - # Step 3: Check if the notification ID was successfully extracted. - if [[ -z "$notification_id" ]]; then - echo "Error: Notification ID not found in the response." - exit 1 - fi + # Step 2: Extract the notification ID from the JSON response + notification_id=$(echo "$response" | jq -r '.notification') - progress=0 - timeout=1800 # Timeout in seconds (30 minutes). - start_time=$(date +%s) # Get the current time in seconds + # Step 3: Check if the notification ID was successfully extracted. + if [[ -z "$notification_id" ]]; then + echo "Error: Notification ID not found in the response." + exit 1 + fi - echo "Please wait while code is being switched..." - # Step 4: Poll the notification status until progress reaches 100. - while [[ "$progress" -lt 100 ]]; do - # Run the notification find command. - notification_response=$(acli api:notifications:find "$notification_id" -n) + progress=0 + timeout=1800 # Timeout in seconds (30 minutes). + start_time=$(date +%s) # Get the current time in seconds - # Extract the progress value. - progress=$(echo "$notification_response" | jq -r '.progress') + echo "Please wait while code is being switched..." + # Step 4: Poll the notification status until progress reaches 100. + while [[ "$progress" -lt 100 ]]; do + # Run the notification find command. + notification_response=$(acli api:notifications:find "$notification_id" -n) - # Display current progress. - #echo "Current progress: $progress%" + # Extract the progress value. + progress=$(echo "$notification_response" | jq -r '.progress') - # Check if we've exceeded the timeout (5 minutes). - current_time=$(date +%s) - elapsed_time=$((current_time - start_time)) + # Display current progress. + #echo "Current progress: $progress%" - if [[ "$elapsed_time" -ge "$timeout" ]]; then - # Calculate minutes and seconds. - minutes=$((elapsed_time / 60)) - seconds=$((elapsed_time % 60)) + # Check if we've exceeded the timeout (5 minutes). + current_time=$(date +%s) + elapsed_time=$((current_time - start_time)) - echo "Error: Timeout reached after $minutes minute(s) and $seconds second(s). Progress did not reach 100%." - exit 1 - fi + if [[ "$elapsed_time" -ge "$timeout" ]]; then + # Calculate minutes and seconds. + minutes=$((elapsed_time / 60)) + seconds=$((elapsed_time % 60)) + + echo "Error: Timeout reached after $minutes minute(s) and $seconds second(s). Progress did not reach 100%." + exit 1 + fi - # Wait for 5 seconds before polling again. - sleep 5 - done + # Wait for 5 seconds before polling again. + sleep 5 + done + fi fi From d3e6f5357b623d8eab3603e697dd7994f6c50023 Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Thu, 5 Dec 2024 01:23:23 +0530 Subject: [PATCH 12/27] ACMS-4329: Try more improvements. --- .github/workflows/deployment.workflow.yml | 36 ++++++++++------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/.github/workflows/deployment.workflow.yml b/.github/workflows/deployment.workflow.yml index e41fb30ef..9eac6f44e 100644 --- a/.github/workflows/deployment.workflow.yml +++ b/.github/workflows/deployment.workflow.yml @@ -70,27 +70,6 @@ jobs: - uses: shivammathur/setup-php@v2 with: php-version: ${{ env.PHP_VERSION }} - - name: Configure SSH keys - run: | - mkdir -p ~/.ssh - echo "${ACQUIA_CLOUD_SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - eval `ssh-agent -s` - ssh-add ~/.ssh/id_rsa - - # Loop through each line in the environment variable. - echo "${ACQUIA_CLOUD_KNOWN_HOSTS}" | while IFS= read -r KNOWN_HOST; do - if [[ -n "${KNOWN_HOST}" ]]; then - CLEANED_HOST=$(echo "${KNOWN_HOST}" | tr -d '\r' | xargs -n1) - ssh-keyscan "${CLEANED_HOST}" >> ~/.ssh/known_hosts 2>/dev/null || { - echo "Warning: Unable to scan host ${CLEANED_HOST}. Skipping." - } - fi - done - shell: bash - env: - ACQUIA_CLOUD_SSH_PRIVATE_KEY: ${{ secrets.ACQUIA_CLOUD_SSH_PRIVATE_KEY }} - ACQUIA_CLOUD_KNOWN_HOSTS: ${{ vars.ACQUIA_CLOUD_KNOWN_HOSTS }} - name: Setup Drupal Project run: | # Download specific version of Drupal Core, if requested. @@ -153,6 +132,21 @@ jobs: acli api:environments:update ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} --lang_version=${PHP_VERSION} -n sleep 10 fi + - name: Configure SSH keys + run: | + mkdir -p ~/.ssh + echo "${ACQUIA_CLOUD_SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + eval `ssh-agent -s` + ssh-add ~/.ssh/id_rsa + + SSH_URL=$(acli api:environments:find ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.ssh_url' | awk -F'[@:]' '{print $2}') + GIT_URL=$(acli api:environments:find ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.vcs.url' | awk -F'[@:]' '{print $2}') + + ssh-keyscan "${SSH_URL}" >> ~/.ssh/known_hosts && ssh-keyscan "${GIT_URL}" >> ~/.ssh/known_hosts + shell: bash + env: + ACQUIA_CLOUD_SSH_PRIVATE_KEY: ${{ secrets.ACQUIA_CLOUD_SSH_PRIVATE_KEY }} - name: Deploy & Switch Code shell: bash run: | From 8cee1541bf34d22dabdfa9f0275cbc8996914929 Mon Sep 17 00:00:00 2001 From: Vishal Khode Date: Thu, 5 Dec 2024 13:51:10 +0530 Subject: [PATCH 13/27] ACMS-4329: Make Drupal Core version as optional. --- .github/workflows/deployment.workflow.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deployment.workflow.yml b/.github/workflows/deployment.workflow.yml index 9eac6f44e..02624a2f6 100644 --- a/.github/workflows/deployment.workflow.yml +++ b/.github/workflows/deployment.workflow.yml @@ -22,10 +22,6 @@ on: - ode8 required: true default: 'dev' - drupal-core: - description: 'Choose Drupal Core Version' - required: true - default: '^11' php-version: description: 'Choose PHP Version' type: choice @@ -36,6 +32,10 @@ on: - "8.4" required: true default: '8.3' + drupal-core: + description: 'Choose Drupal Core Version.' + required: false + default: '^11' download-latest-dependencies: description: 'Download latest dependencies' type: boolean From 0c2add3a655fa422fdfe09992bff8743347a2beb Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Fri, 20 Dec 2024 14:39:45 +0530 Subject: [PATCH 14/27] 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 15/27] 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 16/27] 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 17/27] 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 18/27] 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 19/27] 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 20/27] 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 21/27] 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 22/27] 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 23/27] 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 24/27] 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 25/27] 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 26/27] 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 27/27] 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; } /**