class ConfigSplitImportForm in Configuration Split 2.0.x
The form for importing a split.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\config_split\Form\ConfigSplitImportForm uses ConfigImportFormTrait
Expanded class hierarchy of ConfigSplitImportForm
1 string reference to 'ConfigSplitImportForm'
File
- src/
Form/ ConfigSplitImportForm.php, line 18
Namespace
Drupal\config_split\FormView source
class ConfigSplitImportForm extends FormBase {
use ConfigImportFormTrait;
/**
* The active config storage.
*
* @var \Drupal\Core\Config\StorageInterface
*/
protected $activeStorage;
/**
* The split manager.
*
* @var \Drupal\config_split\ConfigSplitManager
*/
protected $manager;
/**
* The status override service.
*
* @var \Drupal\config_split\Config\StatusOverride
*/
protected $statusOverride;
/**
* The constructor.
*
* @param \Drupal\Core\Config\StorageInterface $activeStorage
* The active config storage.
* @param \Drupal\config_split\ConfigSplitManager $configSplitManager
* The split manager.
* @param \Drupal\config_split\Config\StatusOverride $statusOverride
* The status override service.
*/
public function __construct(StorageInterface $activeStorage, ConfigSplitManager $configSplitManager, StatusOverride $statusOverride) {
$this->activeStorage = $activeStorage;
$this->manager = $configSplitManager;
$this->statusOverride = $statusOverride;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.storage'), $container
->get('config_split.manager'), $container
->get('config_split.status_override'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'config_split_import_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$split = $this
->getSplit();
$comparer = new StorageComparer($this->manager
->singleImport($split, !$split
->get('status')), $this->activeStorage);
$options = [
'route' => [
'config_split' => $split
->getName(),
'operation' => 'import',
],
'operation label' => $this
->t('Import all'),
];
$form = $this
->buildFormWithStorageComparer($form, $form_state, $comparer, $options);
if (!$split
->get('status')) {
$locallyDeactivated = $this->statusOverride
->getSplitOverride($split
->getName()) === FALSE;
$form['activate_local_only'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Activate locally only'),
'#description' => $this
->t('If this is set, the split config will not be made active by default but instead it will be locally overwritten to be active.'),
'#default_value' => !$locallyDeactivated,
];
if ($locallyDeactivated) {
$form['deactivation_notice'] = [
'#type' => 'markup',
'#markup' => $this
->t('The local inactivation state override will be removed'),
];
}
}
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$split = $this
->getSplit();
$activate = !$split
->get('status');
if ($activate) {
if ($form_state
->getValue('activate_local_only')) {
$this->statusOverride
->setSplitOverride($split
->getName(), TRUE);
$activate = FALSE;
}
else {
$this->statusOverride
->setSplitOverride($split
->getName(), NULL);
}
}
$comparer = new StorageComparer($this->manager
->singleImport($split, $activate), $this->activeStorage);
$this
->launchImport($comparer);
}
/**
* Checks access for a specific request.
*
* @param \Drupal\Core\Session\AccountInterface $account
* Run access checks for this account.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(AccountInterface $account) {
$split = $this
->getSplit();
return AccessResult::allowedIfHasPermission($account, 'administer configuration split')
->andIf(AccessResult::allowedIf($split
->get('status') || $split
->get('storage') === 'collection'))
->addCacheableDependency($split);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigImporterTrait:: |
protected | function | Get a config importer from a storage comparer. | |
ConfigImporterTrait:: |
protected | function | Get a config importer from a storage to sync import. | |
ConfigImportFormTrait:: |
protected | function | ||
ConfigImportFormTrait:: |
public static | function | ||
ConfigImportFormTrait:: |
protected | function | Get a split from the route. | |
ConfigImportFormTrait:: |
protected | function | ||
ConfigSplitImportForm:: |
protected | property | The active config storage. | |
ConfigSplitImportForm:: |
protected | property |
The split manager. Overrides ConfigImportFormTrait:: |
|
ConfigSplitImportForm:: |
protected | property | The status override service. | |
ConfigSplitImportForm:: |
public | function | Checks access for a specific request. | |
ConfigSplitImportForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
ConfigSplitImportForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
ConfigSplitImportForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ConfigSplitImportForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
ConfigSplitImportForm:: |
public | function | The constructor. | |
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 3 |
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. | 3 |
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. | |
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:: |
72 |
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. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
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. | 4 |
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. |