You are here

class ModuleConfigureForm in Thunder 6.1.x

Same name and namespace in other branches
  1. 8.5 src/Installer/Form/ModuleConfigureForm.php \Drupal\thunder\Installer\Form\ModuleConfigureForm
  2. 8.2 src/Installer/Form/ModuleConfigureForm.php \Drupal\thunder\Installer\Form\ModuleConfigureForm
  3. 8.3 src/Installer/Form/ModuleConfigureForm.php \Drupal\thunder\Installer\Form\ModuleConfigureForm
  4. 8.4 src/Installer/Form/ModuleConfigureForm.php \Drupal\thunder\Installer\Form\ModuleConfigureForm
  5. 6.2.x src/Installer/Form/ModuleConfigureForm.php \Drupal\thunder\Installer\Form\ModuleConfigureForm
  6. 6.0.x src/Installer/Form/ModuleConfigureForm.php \Drupal\thunder\Installer\Form\ModuleConfigureForm

Provides the site configuration form.

Hierarchy

Expanded class hierarchy of ModuleConfigureForm

1 string reference to 'ModuleConfigureForm'
thunder.routing.yml in ./thunder.routing.yml
thunder.routing.yml

File

src/Installer/Form/ModuleConfigureForm.php, line 23

Namespace

Drupal\thunder\Installer\Form
View source
class ModuleConfigureForm extends FormBase {
  use ModuleDependencyMessageTrait;

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

  /**
   * The module installer.
   *
   * @var \Drupal\Core\Extension\ModuleInstallerInterface
   */
  protected $moduleInstaller;

  /**
   * 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) {
    $form = parent::create($container);
    $form
      ->setModuleExtensionList($container
      ->get('extension.list.module'));
    $form
      ->setModuleInstaller($container
      ->get('module_installer'));
    $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) {
    $this->moduleExtensionList = $moduleExtensionList;
  }

  /**
   * Set the modules installer.
   *
   * @param \Drupal\Core\Extension\ModuleInstallerInterface $moduleInstaller
   *   The module installer.
   */
  protected function setModuleInstaller(ModuleInstallerInterface $moduleInstaller) {
    $this->moduleInstaller = $moduleInstaller;
  }

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

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

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

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

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'thunder_module_configure_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['description'] = [
      '#type' => 'item',
      '#markup' => $this
        ->t('This is a list of modules that are supported by Thunder, but not enabled by default.'),
    ];
    $form['install_modules'] = [
      '#type' => 'container',
      '#tree' => TRUE,
    ];
    $modules = $this->moduleExtensionList
      ->getList();
    $thunder_features = array_filter($modules, function (Extension $module) {
      return $module->info['package'] === 'Thunder Optional';
    });
    foreach ($thunder_features as $id => $module) {
      $form['install_modules'][$id] = [
        '#type' => 'container',
      ];
      $form['install_modules'][$id]['enable'] = [
        '#type' => 'checkbox',
        '#title' => $module->info['name'],
        '#default_value' => $module->status,
        '#disabled' => $module->status,
      ];
      $form['install_modules'][$id]['info'] = [
        '#type' => 'container',
        '#attributes' => [
          'class' => [
            'module-info',
          ],
        ],
      ];
      $form['install_modules'][$id]['info']['description'] = [
        '#markup' => '<span class="text module-description">' . $module->info['description'] . '</span>',
      ];
      $requires = [];

      // If this module requires other modules, add them to the array.

      /** @var \Drupal\Core\Extension\Dependency $dependency_object */
      foreach ($module->requires as $dependency => $dependency_object) {

        // @todo Add logic for not displaying hidden modules in
        //   https://drupal.org/node/3117829.
        if ($incompatible = $this
          ->checkDependencyMessage($modules, $dependency, $dependency_object)) {
          $requires[$dependency] = $incompatible;
          $form['install_modules'][$id]['enable']['#disabled'] = TRUE;
          continue;
        }
        $name = $modules[$dependency]->info['name'];
        $requires[$dependency] = $modules[$dependency]->status ? $this
          ->t('@module', [
          '@module' => $name,
        ]) : $this
          ->t('@module (<span class="admin-disabled">disabled</span>)', [
          '@module' => $name,
        ]);
      }
      $form['install_modules'][$id]['info']['requires'] = [
        '#prefix' => '<div class="admin-requirements">Requires: ',
        '#suffix' => '</div>',
        '#theme' => 'item_list',
        '#items' => $requires,
        '#context' => [
          'list_style' => 'comma-list',
        ],
      ];
      if ($module->status) {

        // 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') && in_array($module
          ->getName(), $this->moduleHandler
          ->getImplementations('help'))) {
          $form['install_modules'][$id]['info']['links']['help'] = [
            '#type' => 'link',
            '#title' => $this
              ->t('Help'),
            '#url' => Url::fromRoute('help.page', [
              'name' => $module
                ->getName(),
            ]),
            '#options' => [
              'attributes' => [
                'class' => [
                  'module-link',
                  'module-link-help',
                ],
                'title' => $this
                  ->t('Help'),
              ],
            ],
          ];
        }

        // Generate link for module's permission, if the user has access to it.
        if ($this->currentUser
          ->hasPermission('administer permissions') && $this->permissionHandler
          ->moduleProvidesPermissions($module
          ->getName())) {
          $form['install_modules'][$id]['info']['links']['permissions'] = [
            '#type' => 'link',
            '#title' => $this
              ->t('Permissions'),
            '#url' => Url::fromRoute('user.admin_permissions'),
            '#options' => [
              'fragment' => 'module-' . $module
                ->getName(),
              'attributes' => [
                'class' => [
                  'module-link',
                  'module-link-permissions',
                ],
                'title' => $this
                  ->t('Configure permissions'),
              ],
            ],
          ];
        }

        // Generate link for module's configuration page, if it has one.
        if (isset($module->info['configure'])) {
          $route_parameters = isset($module->info['configure_parameters']) ? $module->info['configure_parameters'] : [];
          if ($this->accessManager
            ->checkNamedRoute($module->info['configure'], $route_parameters, $this->currentUser)) {
            $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'],
              ]),
              '#url' => Url::fromRoute($module->info['configure'], $route_parameters),
              '#options' => [
                'attributes' => [
                  'class' => [
                    'module-link',
                    'module-link-configure',
                  ],
                ],
              ],
            ];
          }
        }
      }
    }
    $form['#title'] = $this
      ->t('Install & configure modules');
    $form['actions'] = [
      '#type' => 'actions',
    ];
    $form['actions']['save'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Save and continue'),
      '#button_type' => 'primary',
    ];
    $form['#attached']['library'][] = 'thunder/module.configure.form';
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $operations = [];
    foreach ($form_state
      ->getValue('install_modules') as $module => $values) {
      $extension = $this->moduleExtensionList
        ->get($module);
      if (!$extension->status && $values['enable']) {
        $operations[] = [
          [
            $this,
            'batchOperation',
          ],
          [
            $module,
          ],
        ];
      }
    }
    if ($operations) {
      $batch = [
        'operations' => $operations,
        'title' => $this
          ->t('Installing additional modules'),
        'error_message' => $this
          ->t('The installation has encountered an error.'),
      ];
      if (InstallerKernel::installationAttempted()) {
        $buildInfo = $form_state
          ->getBuildInfo();
        $buildInfo['args'][0]['thunder_install_batch'] = $batch;
        $form_state
          ->setBuildInfo($buildInfo);
      }
      else {
        batch_set($batch);
      }
    }
  }

  /**
   * Batch operation callback.
   *
   * @param string $module
   *   Name of the module.
   * @param array $context
   *   The batch context.
   *
   * @throws \Drupal\Core\Extension\MissingDependencyException
   */
  public function batchOperation($module, array &$context) {
    Environment::setTimeLimit(0);
    $this->moduleInstaller
      ->install([
      $module,
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 3
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 3
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route.
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 72
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
ModuleConfigureForm::$accessManager protected property The access manager service.
ModuleConfigureForm::$currentUser protected property The current user.
ModuleConfigureForm::$moduleExtensionList protected property The module extension list.
ModuleConfigureForm::$moduleHandler protected property The module handler service.
ModuleConfigureForm::$moduleInstaller protected property The module installer.
ModuleConfigureForm::$permissionHandler protected property The permission handler service.
ModuleConfigureForm::batchOperation public function Batch operation callback.
ModuleConfigureForm::buildForm public function Form constructor. Overrides FormInterface::buildForm
ModuleConfigureForm::create public static function Instantiates a new instance of this class. Overrides FormBase::create
ModuleConfigureForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
ModuleConfigureForm::setAccessManager protected function Set the access manager.
ModuleConfigureForm::setCurrentUser protected function Set the current user.
ModuleConfigureForm::setModuleExtensionList protected function Set the module extension list.
ModuleConfigureForm::setModuleHandler protected function Set the module handler service.
ModuleConfigureForm::setModuleInstaller protected function Set the modules installer.
ModuleConfigureForm::setPermissionHandler protected function Set the permissions handler service.
ModuleConfigureForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.