class ModulesListNonStableConfirmForm
Builds a confirmation form for enabling experimental and deprecated modules.
@internal
Hierarchy
- class \Drupal\Core\Form\FormBase implements \Drupal\Core\Form\FormInterface, \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait- class \Drupal\Core\Form\ConfirmFormBase implements \Drupal\Core\Form\ConfirmFormInterface extends \Drupal\Core\Form\FormBase- class \Drupal\system\Form\ModulesListConfirmForm uses \Drupal\system\Form\ModulesEnabledTrait extends \Drupal\Core\Form\ConfirmFormBase- class \Drupal\system\Form\ModulesListNonStableConfirmForm extends \Drupal\system\Form\ModulesListConfirmForm
 
 
- class \Drupal\system\Form\ModulesListConfirmForm uses \Drupal\system\Form\ModulesEnabledTrait extends \Drupal\Core\Form\ConfirmFormBase
 
- class \Drupal\Core\Form\ConfirmFormBase implements \Drupal\Core\Form\ConfirmFormInterface extends \Drupal\Core\Form\FormBase
Expanded class hierarchy of ModulesListNonStableConfirmForm
1 string reference to 'ModulesListNonStableConfirmForm'
- system.routing.yml in core/modules/ system/ system.routing.yml 
- core/modules/system/system.routing.yml
File
- 
              core/modules/ system/ src/ Form/ ModulesListNonStableConfirmForm.php, line 20 
Namespace
Drupal\system\FormView source
class ModulesListNonStableConfirmForm extends ModulesListConfirmForm {
  
  /**
   * Module extension list.
   *
   * @var \Drupal\Core\Extension\ModuleExtensionList
   */
  protected $moduleExtensionList;
  
  /**
   * An array of module names to be enabled, keyed by lifecycle.
   *
   * @var array
   */
  protected $groupedModuleInfo;
  
  /**
   * Boolean indicating a core deprecated module is being enabled.
   *
   * @var bool
   */
  protected $coreDeprecatedModules;
  
  /**
   * Boolean indicating a contrib deprecated module is being enabled.
   *
   * @var bool
   */
  protected $contribDeprecatedModules;
  
  /**
   * Constructs a new ModulesListNonStableConfirmForm.
   *
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   * @param \Drupal\Core\Extension\ModuleInstallerInterface $module_installer
   *   The module installer.
   * @param \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $key_value_expirable
   *   The key value expirable factory.
   * @param \Drupal\Core\Extension\ModuleExtensionList $moduleExtensionList
   *   The module extension list.
   */
  public function __construct(ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable, ModuleExtensionList $moduleExtensionList) {
    parent::__construct($module_handler, $module_installer, $key_value_expirable);
    $this->moduleExtensionList = $moduleExtensionList;
  }
  
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container->get('module_handler'), $container->get('module_installer'), $container->get('keyvalue.expirable')
      ->get('module_list'), $container->get('extension.list.module'));
  }
  
  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
    $hasExperimentalModulesToEnable = !empty($this->groupedModuleInfo[ExtensionLifecycle::EXPERIMENTAL]);
    $hasDeprecatedModulesToEnable = !empty($this->groupedModuleInfo[ExtensionLifecycle::DEPRECATED]);
    if ($hasExperimentalModulesToEnable && $hasDeprecatedModulesToEnable) {
      return $this->t('Are you sure you wish to enable experimental and deprecated modules?');
    }
    if ($hasExperimentalModulesToEnable) {
      return $this->formatPlural(count($this->groupedModuleInfo[ExtensionLifecycle::EXPERIMENTAL]), 'Are you sure you wish to enable an experimental module?', 'Are you sure you wish to enable experimental modules?');
    }
    if ($hasDeprecatedModulesToEnable) {
      return $this->formatPlural(count($this->groupedModuleInfo[ExtensionLifecycle::DEPRECATED]), 'Are you sure you wish to enable a deprecated module?', 'Are you sure you wish to enable deprecated modules?');
    }
  }
  
  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'system_modules_non_stable_confirm_form';
  }
  
  /**
   * {@inheritdoc}
   */
  protected function buildMessageList() {
    $this->buildNonStableInfo();
    $items = parent::buildMessageList();
    if (!empty($this->groupedModuleInfo[ExtensionLifecycle::EXPERIMENTAL])) {
      $this->messenger()
        ->addWarning($this->t('<a href=":url">Experimental modules</a> are provided for testing purposes only. Use at your own risk.', [
        ':url' => 'https://www.drupal.org/core/experimental',
      ]));
      // Add the list of experimental modules after any other messages.
      $items[] = $this->formatPlural(count($this->groupedModuleInfo[ExtensionLifecycle::EXPERIMENTAL]), 'The following module is experimental: @modules.', 'The following modules are experimental: @modules.', [
        '@modules' => implode(', ', $this->groupedModuleInfo[ExtensionLifecycle::EXPERIMENTAL]),
      ]);
    }
    if (!empty($this->groupedModuleInfo[ExtensionLifecycle::DEPRECATED])) {
      $this->messenger()
        ->addWarning($this->buildDeprecatedMessage($this->coreDeprecatedModules, $this->contribDeprecatedModules));
      $items = array_merge($items, $this->groupedModuleInfo[ExtensionLifecycle::DEPRECATED]);
    }
    return $items;
  }
  
  /**
   * Builds a message to be displayed to the user enabling deprecated modules.
   *
   * @param bool $core_deprecated_modules
   *   TRUE if a core deprecated module is being enabled.
   * @param bool $contrib_deprecated_modules
   *   TRUE if a contrib deprecated module is being enabled.
   *
   * @return \Drupal\Core\StringTranslation\TranslatableMarkup
   *   The relevant message.
   */
  protected function buildDeprecatedMessage(bool $core_deprecated_modules, bool $contrib_deprecated_modules) : TranslatableMarkup {
    if ($contrib_deprecated_modules && $core_deprecated_modules) {
      return $this->t('<a href=":url">Deprecated modules</a> are modules that may be removed from the next major release of Drupal core and the relevant contributed module. Use at your own risk.', [
        ':url' => 'https://www.drupal.org/about/core/policies/core-change-policies/deprecated-modules-and-themes',
      ]);
    }
    if ($contrib_deprecated_modules) {
      return $this->t('<a href=":url">Deprecated modules</a> are modules that may be removed from the next major release of this project. Use at your own risk.', [
        ':url' => 'https://www.drupal.org/about/core/policies/core-change-policies/deprecated-modules-and-themes',
      ]);
    }
    return $this->t('<a href=":url">Deprecated modules</a> are modules that may be removed from the next major release of Drupal core. Use at your own risk.', [
      ':url' => 'https://www.drupal.org/about/core/policies/core-change-policies/deprecated-modules-and-themes',
    ]);
  }
  
  /**
   * Sets properties with information about non-stable modules being enabled.
   */
  protected function buildNonStableInfo() : void {
    $non_stable = $this->modules['non_stable'];
    $data = $this->moduleExtensionList
      ->getList();
    $grouped = [];
    $core_deprecated_modules = FALSE;
    $contrib_deprecated_modules = FALSE;
    foreach ($non_stable as $machine_name => $name) {
      $lifecycle = $data[$machine_name]->info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER];
      if ($lifecycle === ExtensionLifecycle::EXPERIMENTAL) {
        // We just show the extension name if it is experimental.
        $grouped[$lifecycle][] = $name;
        continue;
      }
      $core_deprecated_modules = $core_deprecated_modules || $data[$machine_name]->origin === 'core';
      $contrib_deprecated_modules = $contrib_deprecated_modules || $data[$machine_name]->origin !== 'core';
      // If the extension is deprecated we show links to more information.
      $grouped[$lifecycle][] = Link::fromTextAndUrl($this->t('The @name module is deprecated. (more information)', [
        '@name' => $name,
      ]), Url::fromUri($data[$machine_name]->info[ExtensionLifecycle::LIFECYCLE_LINK_IDENTIFIER], [
        'attributes' => [
          'aria-label' => ' ' . $this->t('about the status of the @name module', [
            '@name' => $name,
          ]),
        ],
      ]))
        ->toString();
    }
    $this->groupedModuleInfo = $grouped;
    $this->coreDeprecatedModules = $core_deprecated_modules;
    $this->contribDeprecatedModules = $contrib_deprecated_modules;
  }
}Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides | 
|---|---|---|---|---|---|
| ConfirmFormBase::getCancelText | public | function | Returns a caption for the link which cancels the action. | Overrides ConfirmFormInterface::getCancelText | 2 | 
| ConfirmFormBase::getFormName | public | function | Returns the internal name used to refer to the confirmation item. | Overrides ConfirmFormInterface::getFormName | |
| DependencySerializationTrait::$_entityStorages | protected | property | An array of entity type IDs keyed by the property name of their storages. | ||
| DependencySerializationTrait::$_serviceIds | protected | property | An array of service IDs keyed by property name used for serialization. | ||
| DependencySerializationTrait::__sleep | public | function | 2 | ||
| DependencySerializationTrait::__wakeup | public | function | #[\ReturnTypeWillChange] | 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::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 | 73 | 
| 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. | ||
| ModulesEnabledTrait::currentUser | abstract protected | function | Gets the current user. | ||
| ModulesEnabledTrait::modulesEnabledConfirmationMessage | protected | function | Provides a confirmation message after modules have been enabled. | ||
| ModulesEnabledTrait::modulesFailToEnableMessage | protected | function | Provides a fail message after attempt to install a module. | ||
| ModulesListConfirmForm::$keyValueExpirable | protected | property | The expirable key value store. | ||
| ModulesListConfirmForm::$moduleHandler | protected | property | The module handler service. | ||
| ModulesListConfirmForm::$moduleInstaller | protected | property | The module installer. | ||
| ModulesListConfirmForm::$modules | protected | property | An associative list of modules to enable or disable. | ||
| ModulesListConfirmForm::buildForm | public | function | Form constructor. | Overrides ConfirmFormBase::buildForm | |
| ModulesListConfirmForm::getCancelUrl | public | function | Returns the route to go to if the user cancels the action. | Overrides ConfirmFormInterface::getCancelUrl | |
| ModulesListConfirmForm::getConfirmText | public | function | Returns a caption for the button that confirms the action. | Overrides ConfirmFormBase::getConfirmText | |
| ModulesListConfirmForm::getDescription | public | function | Returns additional text to display as a description. | Overrides ConfirmFormBase::getDescription | |
| ModulesListConfirmForm::submitForm | public | function | Form submission handler. | Overrides FormInterface::submitForm | |
| ModulesListNonStableConfirmForm::$contribDeprecatedModules | protected | property | Boolean indicating a contrib deprecated module is being enabled. | ||
| ModulesListNonStableConfirmForm::$coreDeprecatedModules | protected | property | Boolean indicating a core deprecated module is being enabled. | ||
| ModulesListNonStableConfirmForm::$groupedModuleInfo | protected | property | An array of module names to be enabled, keyed by lifecycle. | ||
| ModulesListNonStableConfirmForm::$moduleExtensionList | protected | property | Module extension list. | ||
| ModulesListNonStableConfirmForm::buildDeprecatedMessage | protected | function | Builds a message to be displayed to the user enabling deprecated modules. | ||
| ModulesListNonStableConfirmForm::buildMessageList | protected | function | Builds the message list for the confirmation form. | Overrides ModulesListConfirmForm::buildMessageList | |
| ModulesListNonStableConfirmForm::buildNonStableInfo | protected | function | Sets properties with information about non-stable modules being enabled. | ||
| ModulesListNonStableConfirmForm::create | public static | function | Instantiates a new instance of this class. | Overrides ModulesListConfirmForm::create | |
| ModulesListNonStableConfirmForm::getFormId | public | function | Returns a unique string identifying the form. | Overrides ModulesListConfirmForm::getFormId | |
| ModulesListNonStableConfirmForm::getQuestion | public | function | Returns the question to ask the user. | Overrides ModulesListConfirmForm::getQuestion | |
| ModulesListNonStableConfirmForm::__construct | public | function | Constructs a new ModulesListNonStableConfirmForm. | Overrides ModulesListConfirmForm::__construct | |
| 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. | 3 | |
| 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. | 
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
