Skip to content

Commit

Permalink
No services on the form
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpott committed Feb 14, 2024
1 parent 0f6cf49 commit 5199f86
Showing 1 changed file with 5 additions and 110 deletions.
115 changes: 5 additions & 110 deletions src/Installer/Form/ModuleConfigureForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@
namespace Drupal\thunder\Installer\Form;

use Drupal\Component\Utility\Environment;
use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Extension\Extension;
use Drupal\Core\Extension\ExtensionLifecycle;
use Drupal\Core\Extension\ModuleDependencyMessageTrait;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Url;
use Drupal\user\PermissionHandlerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Provides the site configuration form.
Expand All @@ -24,105 +18,6 @@ class ModuleConfigureForm extends FormBase {

use ModuleDependencyMessageTrait;

/**
* The module extension list.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
protected $moduleExtensionList;

/**
* The access manager service.
*
* @var \Drupal\Core\Access\AccessManagerInterface
*/
protected $accessManager;

/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;

/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;

/**
* The permission handler service.
*
* @var \Drupal\user\PermissionHandlerInterface
*/
protected $permissionHandler;

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container): self {
$form = parent::create($container);
$form->setModuleExtensionList($container->get('extension.list.module'));
$form->setAccessManager($container->get('access_manager'));
$form->setCurrentUser($container->get('current_user'));
$form->setModuleHandler($container->get('module_handler'));
$form->setPermissionHandler($container->get('user.permissions'));
$form->setConfigFactory($container->get('config.factory'));
return $form;
}

/**
* Set the module extension list.
*
* @param \Drupal\Core\Extension\ModuleExtensionList $moduleExtensionList
* The module extension list.
*/
protected function setModuleExtensionList(ModuleExtensionList $moduleExtensionList): void {
$this->moduleExtensionList = $moduleExtensionList;
}

/**
* Set the access manager.
*
* @param \Drupal\Core\Access\AccessManagerInterface $accessManager
* The access manager service.
*/
protected function setAccessManager(AccessManagerInterface $accessManager): void {
$this->accessManager = $accessManager;
}

/**
* Set the current user.
*
* @param \Drupal\Core\Session\AccountProxyInterface $accountProxy
* The current user.
*/
protected function setCurrentUser(AccountProxyInterface $accountProxy): void {
$this->currentUser = $accountProxy;
}

/**
* Set the module handler service.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The module handler service.
*/
protected function setModuleHandler(ModuleHandlerInterface $moduleHandler): void {
$this->moduleHandler = $moduleHandler;
}

/**
* Set the permissions handler service.
*
* @param \Drupal\user\PermissionHandlerInterface $handler
* The permissions handler service.
*/
protected function setPermissionHandler(PermissionHandlerInterface $handler): void {
$this->permissionHandler = $handler;
}

/**
* {@inheritdoc}
*/
Expand All @@ -144,7 +39,7 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
'#tree' => TRUE,
];

$modules = $this->moduleExtensionList->getList();
$modules = \Drupal::service('extension.list.module')->getList();

Check warning on line 42 in src/Installer/Form/ModuleConfigureForm.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal practice)

[drupal-coder (drupal practice)] src/Installer/Form/ModuleConfigureForm.php#L42 <DrupalPractice.Objects.GlobalDrupal.GlobalDrupal>

\Drupal calls should be avoided in classes, use dependency injection instead
Raw output
/github/workspace/src/Installer/Form/ModuleConfigureForm.php:42:17: warning: \Drupal calls should be avoided in classes, use dependency injection instead (DrupalPractice.Objects.GlobalDrupal.GlobalDrupal)
$thunder_features = array_filter($modules, fn(Extension $module): bool => $module->info['package'] === 'Thunder Optional' && (!isset($module->info['hidden']) || !$module->info['hidden']));

foreach ($thunder_features as $id => $module) {
Expand Down Expand Up @@ -205,7 +100,7 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
// Generate link for module's help page. Assume that if a hook_help()
// implementation exists then the module provides an overview page,
// rather than checking to see if the page exists, which is costly.
if ($this->moduleHandler->moduleExists('help') && $this->moduleHandler->hasImplementations('help', $module->getName())) {
if (\Drupal::moduleHandler()->moduleExists('help') && \Drupal::moduleHandler()->hasImplementations('help', $module->getName())) {

Check warning on line 103 in src/Installer/Form/ModuleConfigureForm.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal practice)

[drupal-coder (drupal practice)] src/Installer/Form/ModuleConfigureForm.php#L103 <DrupalPractice.Objects.GlobalDrupal.GlobalDrupal>

\Drupal calls should be avoided in classes, use dependency injection instead
Raw output
/github/workspace/src/Installer/Form/ModuleConfigureForm.php:103:14: warning: \Drupal calls should be avoided in classes, use dependency injection instead (DrupalPractice.Objects.GlobalDrupal.GlobalDrupal)

Check warning on line 103 in src/Installer/Form/ModuleConfigureForm.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal practice)

[drupal-coder (drupal practice)] src/Installer/Form/ModuleConfigureForm.php#L103 <DrupalPractice.Objects.GlobalDrupal.GlobalDrupal>

\Drupal calls should be avoided in classes, use dependency injection instead
Raw output
/github/workspace/src/Installer/Form/ModuleConfigureForm.php:103:64: warning: \Drupal calls should be avoided in classes, use dependency injection instead (DrupalPractice.Objects.GlobalDrupal.GlobalDrupal)
$form['install_modules'][$id]['info']['links']['help'] = [
'#type' => 'link',
'#title' => $this->t('Help'),
Expand All @@ -220,7 +115,7 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
}

// Generate link for module's permission, if the user has access to it.
if ($this->currentUser->hasPermission('administer permissions') && $this->permissionHandler->moduleProvidesPermissions($module->getName())) {
if ($this->currentUser()->hasPermission('administer permissions') && \Drupal::service('user.permissions')->moduleProvidesPermissions($module->getName())) {

Check warning on line 118 in src/Installer/Form/ModuleConfigureForm.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal practice)

[drupal-coder (drupal practice)] src/Installer/Form/ModuleConfigureForm.php#L118 <DrupalPractice.Objects.GlobalDrupal.GlobalDrupal>

\Drupal calls should be avoided in classes, use dependency injection instead
Raw output
/github/workspace/src/Installer/Form/ModuleConfigureForm.php:118:79: warning: \Drupal calls should be avoided in classes, use dependency injection instead (DrupalPractice.Objects.GlobalDrupal.GlobalDrupal)
$form['install_modules'][$id]['info']['links']['permissions'] = [
'#type' => 'link',
'#title' => $this->t('Permissions'),
Expand All @@ -238,7 +133,7 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
// Generate link for module's configuration page, if it has one.
if (isset($module->info['configure'])) {
$route_parameters = $module->info['configure_parameters'] ?? [];
if ($this->accessManager->checkNamedRoute($module->info['configure'], $route_parameters, $this->currentUser)) {
if (\Drupal::service('access_manager')->checkNamedRoute($module->info['configure'], $route_parameters, $this->currentUser())) {

Check warning on line 136 in src/Installer/Form/ModuleConfigureForm.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal practice)

[drupal-coder (drupal practice)] src/Installer/Form/ModuleConfigureForm.php#L136 <DrupalPractice.Objects.GlobalDrupal.GlobalDrupal>

\Drupal calls should be avoided in classes, use dependency injection instead
Raw output
/github/workspace/src/Installer/Form/ModuleConfigureForm.php:136:16: warning: \Drupal calls should be avoided in classes, use dependency injection instead (DrupalPractice.Objects.GlobalDrupal.GlobalDrupal)
$form['install_modules'][$id]['info']['links']['configure'] = [
'#type' => 'link',
'#title' => $this->t('Configure <span class="visually-hidden">the @module module</span>', ['@module' => $module->info['name']]),
Expand Down Expand Up @@ -274,7 +169,7 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
public function submitForm(array &$form, FormStateInterface $form_state): void {
$operations = [];
foreach ($form_state->getValue('install_modules') as $module => $values) {
$extension = $this->moduleExtensionList->get($module);
$extension = \Drupal::service('extension.list.module')->get($module);

Check warning on line 172 in src/Installer/Form/ModuleConfigureForm.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal practice)

[drupal-coder (drupal practice)] src/Installer/Form/ModuleConfigureForm.php#L172 <DrupalPractice.Objects.GlobalDrupal.GlobalDrupal>

\Drupal calls should be avoided in classes, use dependency injection instead
Raw output
/github/workspace/src/Installer/Form/ModuleConfigureForm.php:172:21: warning: \Drupal calls should be avoided in classes, use dependency injection instead (DrupalPractice.Objects.GlobalDrupal.GlobalDrupal)
if (!$extension->status && $values['enable']) {
$operations[] = [
[__CLASS__, 'batchOperation'],
Expand Down

0 comments on commit 5199f86

Please sign in to comment.