|
6 | 6 |
|
7 | 7 | use Drupal\cohesion\Controller\AdministrationController;
|
8 | 8 | use Drupal\cohesion_sync\Services\PackageImportHandler;
|
| 9 | +use Drupal\Component\Render\PlainTextOutput; |
9 | 10 | use Drupal\Core\Config\Action\Attribute\ConfigAction;
|
10 | 11 | use Drupal\Core\Config\Action\ConfigActionPluginInterface;
|
11 | 12 | use Drupal\Core\Config\ConfigFactoryInterface;
|
12 | 13 | use Drupal\Core\Extension\ModuleHandler;
|
13 | 14 | use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
14 | 15 | use Drupal\Core\Site\Settings;
|
15 | 16 | use Drupal\Core\StringTranslation\TranslatableMarkup;
|
| 17 | +use Symfony\Component\Console\Input\ArgvInput; |
| 18 | +use Symfony\Component\Console\Output\ConsoleOutput; |
| 19 | +use Symfony\Component\Console\Style\SymfonyStyle; |
16 | 20 | use Symfony\Component\DependencyInjection\ContainerInterface;
|
17 | 21 |
|
18 | 22 | /**
|
@@ -61,7 +65,6 @@ public static function create(ContainerInterface $container, array $configuratio
|
61 | 65 | */
|
62 | 66 | public function apply(string $configName, mixed $value): void {
|
63 | 67 | if ($configName === 'cohesion.settings' && $value) {
|
64 |
| - // Update the configuration with the API and organization keys. |
65 | 68 | $this->updateConfig($configName);
|
66 | 69 | }
|
67 | 70 | }
|
@@ -90,8 +93,35 @@ private function updateConfig(string $configName): void {
|
90 | 93 | ->set('organization_key', $orgKey)
|
91 | 94 | ->save(TRUE);
|
92 | 95 |
|
93 |
| - // Import the base packages. |
94 |
| - $this->importBasePackages(); |
| 96 | + if (PHP_SAPI === 'cli' && !function_exists('drush_backend_batch_process')) { |
| 97 | + $this->notifyManualImport(); |
| 98 | + } else { |
| 99 | + $this->importBasePackages(); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Notifies the user to import packages manually from the UI. |
| 105 | + */ |
| 106 | + private function notifyManualImport(): void { |
| 107 | + $output = new SymfonyStyle(new ArgvInput(), new ConsoleOutput()); |
| 108 | + $output->warning($this->toPlainString( |
| 109 | + t('Please import site studio packages from UI: @uri.', [ |
| 110 | + '@uri' => '/admin/cohesion/configuration/account-settings' |
| 111 | + ]))); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Converts a stringable like TranslatableMarkup to a plain text string. |
| 116 | + * |
| 117 | + * @param \Stringable|string $text |
| 118 | + * The string to convert. |
| 119 | + * |
| 120 | + * @return string |
| 121 | + * The plain text string. |
| 122 | + */ |
| 123 | + private function toPlainString(\Stringable|string $text): string { |
| 124 | + return PlainTextOutput::renderFromHtml((string) $text); |
95 | 125 | }
|
96 | 126 |
|
97 | 127 | /**
|
|
0 commit comments