class ThemeUninstallConfirmForm
Same name and namespace in other branches
- main core/modules/system/src/Form/ThemeUninstallConfirmForm.php \Drupal\system\Form\ThemeUninstallConfirmForm
Builds a confirmation form to uninstall a theme.
@internal
Hierarchy
- class \Drupal\Core\Form\FormBase implements \Drupal\Core\Form\FormInterface, \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\DependencyInjection\AutowireTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Htmx\HtmxRequestInfoTrait, \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\ThemeUninstallConfirmForm uses \Drupal\Core\DependencyInjection\AutowireTrait, \Drupal\Core\Config\Entity\ConfigDependencyDeleteFormTrait extends \Drupal\Core\Form\ConfirmFormBase
- class \Drupal\Core\Form\ConfirmFormBase implements \Drupal\Core\Form\ConfirmFormInterface extends \Drupal\Core\Form\FormBase
Expanded class hierarchy of ThemeUninstallConfirmForm
1 string reference to 'ThemeUninstallConfirmForm'
- system.routing.yml in core/
modules/ system/ system.routing.yml - core/modules/system/system.routing.yml
File
-
core/
modules/ system/ src/ Form/ ThemeUninstallConfirmForm.php, line 26
Namespace
Drupal\system\FormView source
class ThemeUninstallConfirmForm extends ConfirmFormBase {
use AutowireTrait;
use ConfigDependencyDeleteFormTrait;
/**
* The theme label.
*/
protected string $themeLabel = '';
public function __construct(protected ThemeHandlerInterface $themeHandler, protected ThemeInstallerInterface $themeInstaller, protected ConfigManagerInterface $configManager, protected EntityTypeManagerInterface $entityTypeManager) {
}
/**
* {@inheritdoc}
*/
public function getQuestion() : TranslatableMarkup {
if ($this->themeLabel) {
return $this->t('Uninstall %theme theme', [
'%theme' => $this->themeLabel,
]);
}
return $this->t('Uninstall theme');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() : TranslatableMarkup {
return $this->t('Uninstall');
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() : Url {
return new Url('system.themes_page');
}
/**
* {@inheritdoc}
*/
public function getDescription() : TranslatableMarkup {
return $this->t('Would you like to continue with uninstalling the above?');
}
/**
* {@inheritdoc}
*/
public function getFormId() : string {
return 'system_theme_uninstall_confirm_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, #[MapQueryParameter] string $theme = '') : RedirectResponse|array {
if (empty($theme)) {
throw new AccessDeniedHttpException();
}
// Get current list of themes.
$themes = $this->themeHandler
->listInfo();
if (empty($themes[$theme])) {
$this->messenger()
->addError($this->t('The %theme theme was not found.', [
'%theme' => $theme,
]));
return new RedirectResponse($this->getCancelUrl()
->toString());
}
$this->themeLabel = $themes[$theme]->info['name'];
$config = $this->config('system.theme');
if ($theme === $config->get('default')) {
$this->messenger()
->addError($this->t('%theme is the default theme and cannot be uninstalled.', [
'%theme' => $themes[$theme]->info['name'],
]));
return new RedirectResponse($this->getCancelUrl()
->toString());
}
if ($theme === $config->get('admin')) {
$this->messenger()
->addError($this->t('%theme is the admin theme and cannot be uninstalled.', [
'%theme' => $themes[$theme]->info['name'],
]));
return new RedirectResponse($this->getCancelUrl()
->toString());
}
$theme_info = $themes[$theme];
$dependent_themes = [];
if (!empty($theme_info->sub_themes)) {
foreach ($theme_info->sub_themes as $sub_theme => $sub_label) {
if (!empty($themes[$sub_theme]->status)) {
$dependent_themes[] = $sub_label;
}
}
}
if (!empty($dependent_themes)) {
$this->messenger()
->addError($this->t('%theme cannot be uninstalled because the following themes depend on it: %themes', [
'%theme' => $theme_info->info['name'],
'%themes' => implode(', ', $dependent_themes),
]));
return new RedirectResponse($this->getCancelUrl()
->toString());
}
$form['text']['#markup'] = '<p>' . $this->t('The <em>%theme</em> theme will be completely uninstalled from your site, and all data from this theme will be lost!', [
'%theme' => $theme_info->info['name'],
]) . '</p>';
// List the dependent entities.
$this->addDependencyListsToForm($form, 'theme', [
$theme,
], $this->configManager, $this->entityTypeManager);
$form['theme'] = [
'#type' => 'value',
'#value' => $theme,
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) : void {
$themes = $this->themeHandler
->listInfo();
$theme = $form_state->getValue('theme');
$this->themeInstaller
->uninstall([
$form_state->getValue('theme'),
]);
$this->messenger()
->addStatus($this->t('The %theme theme has been uninstalled.', [
'%theme' => $themes[$theme]->info['name'],
]));
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
|---|---|---|---|---|---|
| AutowiredInstanceTrait::createInstanceAutowired | public static | function | Instantiates a new instance of the implementing class using autowiring. | ||
| AutowiredInstanceTrait::getAutowireArguments | private static | function | Resolves arguments for a method using autowiring. | ||
| AutowireTrait::create | public static | function | Instantiates a new instance of the implementing class using autowiring. | 136 | |
| ConfigDependencyDeleteFormTrait::addDependencyListsToForm | protected | function | Adds form elements to list affected configuration entities. | ||
| ConfigDependencyDeleteFormTrait::t | abstract protected | function | Translates a string to the current language or to a given language. | ||
| 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 | 2 | ||
| FormBase::$configFactory | protected | property | The config factory. | 1 | |
| 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. | 1 | |
| FormBase::container | private | function | Returns the service container. | ||
| FormBase::currentUser | protected | function | Gets the current user. | 2 | |
| FormBase::getRequest | protected | function | Gets the request object. | Overrides HtmxRequestInfoTrait::getRequest | |
| 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 | 55 |
| HtmxRequestInfoTrait::getHtmxCurrentUrl | protected | function | Retrieves the URL of the requesting page from an HTMX request header. | ||
| HtmxRequestInfoTrait::getHtmxPrompt | protected | function | Retrieves the prompt from an HTMX request header. | ||
| HtmxRequestInfoTrait::getHtmxTarget | protected | function | Retrieves the target identifier from an HTMX request header. | ||
| HtmxRequestInfoTrait::getHtmxTrigger | protected | function | Retrieves the trigger identifier from an HTMX request header. | ||
| HtmxRequestInfoTrait::getHtmxTriggerName | protected | function | Retrieves the trigger name from an HTMX request header. | ||
| HtmxRequestInfoTrait::isHtmxBoosted | protected | function | Determines if the request is boosted by HTMX. | ||
| HtmxRequestInfoTrait::isHtmxHistoryRestoration | protected | function | Determines if if the request is for history restoration. | ||
| HtmxRequestInfoTrait::isHtmxRequest | protected | function | Determines if the request is sent by HTMX. | ||
| 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. | ||
| RedirectDestinationTrait::$redirectDestination | protected | property | The redirect destination service. | 2 | |
| 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 | |
| ThemeUninstallConfirmForm::$themeLabel | protected | property | The theme label. | ||
| ThemeUninstallConfirmForm::buildForm | public | function | Form constructor. | Overrides ConfirmFormBase::buildForm | |
| ThemeUninstallConfirmForm::getCancelUrl | public | function | Returns the route to go to if the user cancels the action. | Overrides ConfirmFormInterface::getCancelUrl | |
| ThemeUninstallConfirmForm::getConfirmText | public | function | Returns a caption for the button that confirms the action. | Overrides ConfirmFormBase::getConfirmText | |
| ThemeUninstallConfirmForm::getDescription | public | function | Returns additional text to display as a description. | Overrides ConfirmFormBase::getDescription | |
| ThemeUninstallConfirmForm::getFormId | public | function | Returns a unique string identifying the form. | Overrides FormInterface::getFormId | |
| ThemeUninstallConfirmForm::getQuestion | public | function | Returns the question to ask the user. | Overrides ConfirmFormInterface::getQuestion | |
| ThemeUninstallConfirmForm::submitForm | public | function | Form submission handler. | Overrides FormInterface::submitForm | |
| ThemeUninstallConfirmForm::__construct | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.