class ConfigSyncInitialize in Configuration Synchronizer 8
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\config_sync\Form\ConfigSyncInitialize
Expanded class hierarchy of ConfigSyncInitialize
1 string reference to 'ConfigSyncInitialize'
File
- src/
Form/ ConfigSyncInitialize.php, line 14
Namespace
Drupal\config_sync\FormView source
class ConfigSyncInitialize extends FormBase {
/**
* The configuration synchronizer initializer.
*
* @var \Drupal\config_sync\configSyncInitializerInterface
*/
protected $configSyncInitializer;
/**
* The configuration synchronizer lister.
*
* @var \Drupal\config_sync\configSyncListerInterface
*/
protected $configSyncLister;
/**
* The configuration update lister.
*
* @var \Drupal\config_update\ConfigListInterface
*/
protected $configUpdateLister;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface
*/
protected $themeHandler;
/**
* Constructs a new ConfigSync object.
*
* @param \Drupal\config_sync\ConfigSyncInitializerInterface $config_sync_initializer
* The configuration synchronizer initializer.
* @param \Drupal\config_sync\ConfigSyncListerInterface $config_sync_lister
* The configuration synchronizer lister.
* @param \Drupal\config_update\ConfigListInterface $config_update_lister
* The configuration update lister.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler.
*/
public function __construct(ConfigSyncInitializerInterface $config_sync_initializer, ConfigSyncListerInterface $config_sync_lister, ConfigUpdateListerInterface $config_update_lister, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) {
$this->configSyncInitializer = $config_sync_initializer;
$this->configSyncLister = $config_sync_lister;
$this->configUpdateLister = $config_update_lister;
$this->moduleHandler = $module_handler;
$this->themeHandler = $theme_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config_sync.initializer'), $container
->get('config_sync.lister'), $container
->get('config_update.config_list'), $container
->get('module_handler'), $container
->get('theme_handler'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'config_sync_initialize';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$changelists = $this->configSyncLister
->getExtensionChangelists();
if (!empty($changelists)) {
foreach ($changelists as $type => $extension_changelists) {
$form[$type] = $this
->buildUpdatesListing($type, $extension_changelists);
}
$form['retain_active_overrides'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Retain customizations'),
'#default_value' => TRUE,
'#description' => $this
->t('If you select this option, configuration updates will be merged into the active configuration, retaining any customizations.'),
];
$form['message'] = [
'#markup' => $this
->t('Use the button below to initialize data to be imported from updated modules and themes.'),
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Initialize'),
];
}
else {
$form['message'] = [
'#markup' => $this
->t('No configuration updates are available from installed modules and themes.'),
];
}
return $form;
}
/**
* Builds the portion of the form showing a listing of updates.
*
* @param string $type
* The type of extension (module or theme).
* @param array $extension_changelists
* Associative array of configuration changes keyed by extension name.
*
* @return array
* A render array of a form element.
*/
protected function buildUpdatesListing($type, array $extension_changelists) {
$type_labels = [
'module' => $this
->t('Module'),
'theme' => $this
->t('Theme'),
];
$header = [
'name' => [
'data' => $this
->t('@type name', [
'@type' => $type_labels[$type],
]),
],
'details' => [
'data' => $this
->t('Available configuration changes'),
'class' => [
RESPONSIVE_PRIORITY_LOW,
],
],
];
$options = [];
$rows = [];
foreach ($extension_changelists as $name => $changelist) {
$options[$name] = $this
->buildExtensionDetail($type, $name, $changelist);
}
$element = [
// @todo: convert to a tableselect once we refresh the extension
// snapshot values of a given config item on update.
// '#type' => 'tableselect',
'#type' => 'table',
'#header' => $header,
// '#options' => $options,
'#rows' => $options,
'#attributes' => [
'class' => [
'config-sync-listing',
],
],
'#default_value' => array_fill_keys(array_keys($options), TRUE),
];
return $element;
}
/**
* Builds the details of a package.
*
* @param string $type
* The type of extension (module or theme).
* @param string $name
* The machine name of the extension.
* @param array $changelist
* Associative array of configuration changes keyed by the type of change.
*
* @return array
* A render array of a form element.
*/
protected function buildExtensionDetail($type, $name, $changelist) {
switch ($type) {
case 'module':
$label = $this->moduleHandler
->getName($name);
break;
case 'theme':
$label = $this->themeHandler
->getName($name);
break;
}
$element['name'] = [
'data' => [
'#type' => 'html_tag',
'#tag' => 'h3',
'#value' => $label,
],
'class' => [
'config-sync-extension-name',
],
];
$extension_config = [];
foreach ([
'create',
'update',
] as $change_type) {
if (isset($changelist[$change_type])) {
$extension_config[$change_type] = [];
foreach ($changelist[$change_type] as $item_name => $item_label) {
$config_type = $this->configUpdateLister
->getTypeNameByConfigName($item_name);
if (!$config_type) {
$config_type = 'system_simple';
}
if (!isset($extension_config[$change_type][$config_type])) {
$extension_config[$change_type][$config_type] = [];
}
$extension_config[$change_type][$config_type][$item_name] = [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => $item_label,
'#attributes' => [
'title' => $item_name,
'class' => [
'config-sync-item',
],
],
];
}
}
}
$rows = [];
$change_type_labels = [
// Match the labels used by core.
// @see ConfigSync::buildForm().
'create' => $this
->t('New'),
'update' => $this
->t('Changed'),
];
// List config types for order.
$config_types = $this->configSyncLister
->listConfigTypes();
foreach ($extension_config as $change_type => $change_type_data) {
$rows[] = [
[
'data' => [
'#type' => 'html_tag',
'#tag' => 'strong',
'#value' => $change_type_labels[$change_type],
],
'colspan' => 2,
],
];
foreach ($config_types as $config_type => $config_type_label) {
if (isset($change_type_data[$config_type])) {
$row = [];
$row[] = [
'data' => [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => $config_type_label,
'#attributes' => [
'title' => $config_type,
'class' => [
'config-sync-item-label',
],
],
],
];
$row[] = [
'data' => [
'#theme' => 'item_list',
'#items' => $change_type_data[$config_type],
'#context' => [
'list_style' => 'comma-list',
],
],
'class' => [
'item',
],
];
$rows[] = $row;
}
}
}
$element['details'] = [
'data' => [
'#type' => 'table',
'#rows' => $rows,
],
];
return $element;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// @todo: feed second argument to ::initialize.
$this->configSyncInitializer
->initialize($form_state
->getValue('retain_active_overrides'));
$form_state
->setRedirect('config_sync.import');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigSyncInitialize:: |
protected | property | The configuration synchronizer initializer. | |
ConfigSyncInitialize:: |
protected | property | The configuration synchronizer lister. | |
ConfigSyncInitialize:: |
protected | property | The configuration update lister. | |
ConfigSyncInitialize:: |
protected | property | The module handler. | |
ConfigSyncInitialize:: |
protected | property | The theme handler. | |
ConfigSyncInitialize:: |
protected | function | Builds the details of a package. | |
ConfigSyncInitialize:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
ConfigSyncInitialize:: |
protected | function | Builds the portion of the form showing a listing of updates. | |
ConfigSyncInitialize:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
ConfigSyncInitialize:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ConfigSyncInitialize:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
ConfigSyncInitialize:: |
public | function | Constructs a new ConfigSync object. | |
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 config factory. | 1 |
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. | |
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. |