class PanopolyThemeSelectionForm in Panopoly 8.2
Provides a form to choose the starting theme.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\panopoly_theme\Form\PanopolyThemeSelectionForm
Expanded class hierarchy of PanopolyThemeSelectionForm
1 file declares its use of PanopolyThemeSelectionForm
- panopoly_theme.profile.inc in modules/
panopoly/ panopoly_theme/ panopoly_theme.profile.inc - Provides an install task for selection a default theme.
File
- modules/
panopoly/ panopoly_theme/ src/ Form/ PanopolyThemeSelectionForm.php, line 17
Namespace
Drupal\panopoly_theme\FormView source
class PanopolyThemeSelectionForm extends FormBase {
/**
* The theme handler service.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface
*/
protected $themeHandler;
/**
* The renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* The theme installer service.
*
* @var \Drupal\Core\Extension\ThemeInstallerInterface
*/
protected $themeInstaller;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* PanopolyThemeSelectionForm constructor.
*
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler service.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
* @param \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer
* The theme installer service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(ThemeHandlerInterface $theme_handler, RendererInterface $renderer, ThemeInstallerInterface $theme_installer, ConfigFactoryInterface $config_factory) {
$this->themeHandler = $theme_handler;
$this->renderer = $renderer;
$this->themeInstaller = $theme_installer;
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('theme_handler'), $container
->get('renderer'), $container
->get('theme_installer'), $container
->get('config.factory'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'panopoly_theme_selection_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Clear all status messages generated by modules installed in the previous
// step.
$this
->messenger()
->deleteByType(MessengerInterface::TYPE_STATUS);
$form['#title'] = $this
->t('Choose a theme');
$options = [];
foreach ($this->themeHandler
->rebuildThemeData() as $theme) {
// Filter hidden, test and incompatible themes.
// This assumes test themes has 'test' in their name.
if (!empty($theme->info['hidden']) || strpos($theme
->getName(), 'test') !== FALSE) {
continue;
}
// Build a label with name, description and screenshot.
$label = [
'#type' => 'inline_template',
'#template' => '{{ screenshot }}<span><strong>{{ name }}</strong><p>{{ description }}</p></span>',
'#context' => [
'name' => [
'#markup' => $theme->info['name'],
],
'description' => [
'#markup' => $theme->info['description'],
],
'screenshot' => [
'#theme' => 'image',
'#uri' => file_exists($theme->info['screenshot']) ? $theme->info['screenshot'] : drupal_get_path('module', 'system') . '/images/no_screenshot.png',
'#width' => 100,
'#alt' => $theme->info['name'],
],
],
];
$options[$theme
->getName()] = $this->renderer
->renderPlain($label);
}
$form['theme'] = [
'#type' => 'radios',
'#title' => $this
->t('Choose a theme'),
'#title_display' => 'invisible',
'#required' => TRUE,
'#options' => $options,
'#default_value' => 'bartik',
];
$form['submit'] = [
'#type' => 'submit',
'#button_type' => 'primary',
'#value' => $this
->t('Save and continue'),
];
$form['#attached']['library'][] = 'panopoly_theme/selection_form';
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Set the default theme.
if ($theme = $form_state
->getValue('theme')) {
$this->themeInstaller
->install([
$theme,
]);
$this->configFactory
->getEditable('system.theme')
->set('default', $theme)
->save();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PanopolyThemeSelectionForm:: |
protected | property |
The config factory. Overrides FormBase:: |
|
PanopolyThemeSelectionForm:: |
protected | property | The renderer service. | |
PanopolyThemeSelectionForm:: |
protected | property | The theme handler service. | |
PanopolyThemeSelectionForm:: |
protected | property | The theme installer service. | |
PanopolyThemeSelectionForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
PanopolyThemeSelectionForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
PanopolyThemeSelectionForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
PanopolyThemeSelectionForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
PanopolyThemeSelectionForm:: |
public | function | PanopolyThemeSelectionForm constructor. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |