Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: 'Disable Package Manager'
type: module
description: 'Disables Package Manager operations on Acquia hosting.'
hidden: true
core_version_requirement: ^11
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
Drupal\acquia_disable_package_manager\AhPackageManagerDisabler:
tags:
- { name: event_subscriber }
- { name: config.factory.override }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "acquia/acquia_disable_package_manager",
"description": "A hidden Drupal module to disable Package Manager operations on Acquia hosting.",
"type": "drupal-module",
"require": {
"acquia/drupal-environment-detector": "^1.8"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

declare(strict_types=1);

namespace Drupal\acquia_disable_package_manager;

use Acquia\DrupalEnvironmentDetector\AcquiaDrupalEnvironmentDetector;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\SandboxValidationEvent;
use Drupal\package_manager\Event\StatusCheckEvent;
use Drupal\package_manager\Validator\BaseRequirementsFulfilledValidator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* Disables Project Browser and unattended automatic updates on Acquia hosting.
*/
final class AhPackageManagerDisabler implements ConfigFactoryOverrideInterface, EventSubscriberInterface {

use StringTranslationTrait;

/**
* {@inheritdoc}
*/
public static function getSubscribedEvents(): array {
$events = [];

// If Package Manager is disabled, this class won't exist.
if (class_exists(SandboxValidationEvent::class)) {
$events[StatusCheckEvent::class] = $events[PreCreateEvent::class] = [
'disable',
// Run before any other validation.
BaseRequirementsFulfilledValidator::PRIORITY + 100,
];
}
return $events;
}

/**
* Warns (or errs) because Package Manager is disabled on Acquia hosting.
*/
public function disable(SandboxValidationEvent $event): void {
if (AcquiaDrupalEnvironmentDetector::isAhEnv()) {
$event->addError([
$this->t('Package Manager is disabled on Acquia hosting.'),
]);
// Stop all further validation.
$event->stopPropagation();
}
}

/**
* {@inheritdoc}
*/
public function loadOverrides($names): array {
$overrides = [];

if (AcquiaDrupalEnvironmentDetector::isAhEnv()) {
if (in_array('project_browser.admin_settings', $names, TRUE)) {
$overrides['project_browser.admin_settings']['allow_ui_install'] = FALSE;
}
if (in_array('automatic_updates.settings', $names, TRUE)) {
$overrides['automatic_updates.settings']['unattended']['level'] = 'disable';
$overrides['automatic_updates.settings']['allow_core_minor_updates'] = FALSE;
}
}
return $overrides;
}

/**
* {@inheritdoc}
*/
public function getCacheSuffix(): string {
return 'acquia';
}

/**
* {@inheritdoc}
*/
public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION): null {
return NULL;
}

/**
* {@inheritdoc}
*/
public function getCacheableMetadata($name): CacheableMetadata {
return new CacheableMetadata();
}

}
3 changes: 2 additions & 1 deletion recipes/custom/acquia_trials/recipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ name: Acquia Trials
type: Acquia
description: 'Enables Acquia Trials extensions: countdown banner, getting-started checklist, and Cloud Platform promotion block.'
install:
- acquia_trials_countdown
- acquia_disable_package_manager
- acquia_trials_checklist
- acquia_trials_countdown
- acquia_trials_cloud_platform
- acquia_trials_id
config:
Expand Down
Loading