Loading core/modules/system/src/Form/ModulesEnabledTrait.php +26 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\system\Form; use Drupal\Core\Config\PreExistingConfigException; use Drupal\Core\StringTranslation\PluralTranslatableMarkup; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; Loading Loading @@ -57,4 +58,29 @@ protected function modulesEnabledConfirmationMessage(array $modules): PluralTran ); } /** * Provides a fail message after attempt to install a module. * * @param string[] $modules * Enabled module names, keyed by machine names. * @param Drupal\Core\Config\PreExistingConfigException $exception * Exception thrown if configuration with the same name already exists. * * @return \Drupal\Core\StringTranslation\PluralTranslatableMarkup * A confirmation message. If any of the enabled modules have permissions * that the current user can manage, then include a link to the permissions * page for those modules. */ protected function modulesFailToEnableMessage(array $modules, PreExistingConfigException $exception): PluralTranslatableMarkup { $config_objects = $exception->flattenConfigObjects($exception->getConfigObjects()); return $this->formatPlural( count($config_objects), 'Unable to install @extension, %config_names already exists in active configuration.', 'Unable to install @extension, %config_names already exist in active configuration.', [ '%config_names' => implode(', ', $config_objects), '@extension' => $modules['install'][$exception->getExtension()], ]); } } core/modules/system/src/Form/ModulesListConfirmForm.php +1 −11 Original line number Diff line number Diff line Loading @@ -175,17 +175,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $this->moduleInstaller->install(array_keys($this->modules['install'])); } catch (PreExistingConfigException $e) { $config_objects = $e->flattenConfigObjects($e->getConfigObjects()); $this->messenger()->addError( $this->formatPlural( count($config_objects), 'Unable to install @extension, %config_names already exists in active configuration.', 'Unable to install @extension, %config_names already exist in active configuration.', [ '%config_names' => implode(', ', $config_objects), '@extension' => $this->modules['install'][$e->getExtension()], ]) ); $this->messenger()->addError($this->modulesFailToEnableMessage($this->modules, $e)); return; } catch (UnmetDependenciesException $e) { Loading core/modules/system/src/Form/ModulesListForm.php +1 −11 Original line number Diff line number Diff line Loading @@ -477,17 +477,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ->addStatus($this->modulesEnabledConfirmationMessage($modules['install'])); } catch (PreExistingConfigException $e) { $config_objects = $e->flattenConfigObjects($e->getConfigObjects()); $this->messenger()->addError( $this->formatPlural( count($config_objects), 'Unable to install @extension, %config_names already exists in active configuration.', 'Unable to install @extension, %config_names already exist in active configuration.', [ '%config_names' => implode(', ', $config_objects), '@extension' => $modules['install'][$e->getExtension()], ]) ); $this->messenger()->addError($this->modulesFailToEnableMessage($modules, $e)); return; } catch (UnmetDependenciesException $e) { Loading Loading
core/modules/system/src/Form/ModulesEnabledTrait.php +26 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\system\Form; use Drupal\Core\Config\PreExistingConfigException; use Drupal\Core\StringTranslation\PluralTranslatableMarkup; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; Loading Loading @@ -57,4 +58,29 @@ protected function modulesEnabledConfirmationMessage(array $modules): PluralTran ); } /** * Provides a fail message after attempt to install a module. * * @param string[] $modules * Enabled module names, keyed by machine names. * @param Drupal\Core\Config\PreExistingConfigException $exception * Exception thrown if configuration with the same name already exists. * * @return \Drupal\Core\StringTranslation\PluralTranslatableMarkup * A confirmation message. If any of the enabled modules have permissions * that the current user can manage, then include a link to the permissions * page for those modules. */ protected function modulesFailToEnableMessage(array $modules, PreExistingConfigException $exception): PluralTranslatableMarkup { $config_objects = $exception->flattenConfigObjects($exception->getConfigObjects()); return $this->formatPlural( count($config_objects), 'Unable to install @extension, %config_names already exists in active configuration.', 'Unable to install @extension, %config_names already exist in active configuration.', [ '%config_names' => implode(', ', $config_objects), '@extension' => $modules['install'][$exception->getExtension()], ]); } }
core/modules/system/src/Form/ModulesListConfirmForm.php +1 −11 Original line number Diff line number Diff line Loading @@ -175,17 +175,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $this->moduleInstaller->install(array_keys($this->modules['install'])); } catch (PreExistingConfigException $e) { $config_objects = $e->flattenConfigObjects($e->getConfigObjects()); $this->messenger()->addError( $this->formatPlural( count($config_objects), 'Unable to install @extension, %config_names already exists in active configuration.', 'Unable to install @extension, %config_names already exist in active configuration.', [ '%config_names' => implode(', ', $config_objects), '@extension' => $this->modules['install'][$e->getExtension()], ]) ); $this->messenger()->addError($this->modulesFailToEnableMessage($this->modules, $e)); return; } catch (UnmetDependenciesException $e) { Loading
core/modules/system/src/Form/ModulesListForm.php +1 −11 Original line number Diff line number Diff line Loading @@ -477,17 +477,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ->addStatus($this->modulesEnabledConfirmationMessage($modules['install'])); } catch (PreExistingConfigException $e) { $config_objects = $e->flattenConfigObjects($e->getConfigObjects()); $this->messenger()->addError( $this->formatPlural( count($config_objects), 'Unable to install @extension, %config_names already exists in active configuration.', 'Unable to install @extension, %config_names already exist in active configuration.', [ '%config_names' => implode(', ', $config_objects), '@extension' => $modules['install'][$e->getExtension()], ]) ); $this->messenger()->addError($this->modulesFailToEnableMessage($modules, $e)); return; } catch (UnmetDependenciesException $e) { Loading