class BackupMigrateAdvancedBackupForm in Backup and Migrate 5.0.x
Same name and namespace in other branches
- 8.4 src/Form/BackupMigrateAdvancedBackupForm.php \Drupal\backup_migrate\Form\BackupMigrateAdvancedBackupForm
Provides a form for performing a 1-click site backup.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\backup_migrate\Form\BackupMigrateAdvancedBackupForm
Expanded class hierarchy of BackupMigrateAdvancedBackupForm
1 string reference to 'BackupMigrateAdvancedBackupForm'
File
- src/
Form/ BackupMigrateAdvancedBackupForm.php, line 12
Namespace
Drupal\backup_migrate\FormView source
class BackupMigrateAdvancedBackupForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'backup_migrate_ui_manual_backup_advanced';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Leave a message about the Entire Site backup.
// @see https://www.drupal.org/project/backup_migrate/issues/3151290
$this
->messenger()
->addMessage($this
->t('It is recommended to not use the "Entire site" backup as it has a tendency of failing on anything but the tiniest of sites. Hopefully this will be fixed in a future release.'));
$form = [];
// Theme the form if we want it inline.
// @FIXME
// $form['#theme'] = 'backup_migrate_ui_manual_quick_backup_form_inline';
$bam = backup_migrate_get_service_object();
$form['source'] = [
'#type' => 'fieldset',
"#title" => $this
->t("Source"),
"#collapsible" => TRUE,
"#collapsed" => FALSE,
"#tree" => FALSE,
];
$form['source']['source_id'] = DrupalConfigHelper::getSourceSelector($bam, $this
->t('Backup Source'));
$form['source']['source_id']['#default_value'] = \Drupal::config('backup_migrate.settings')
->get('backup_migrate_source_id');
$form += DrupalConfigHelper::buildAllPluginsForm($bam
->plugins(), 'backup');
if (\Drupal::moduleHandler()
->moduleExists('token')) {
$filename_token = [
'#theme' => 'token_tree_link',
'#token_types' => [
'site',
],
'#dialog' => TRUE,
'#click_insert' => TRUE,
'#show_restricted' => TRUE,
'#group' => 'file',
];
}
else {
$filename_token = [
'#type' => 'markup',
'#markup' => 'In order to use tokens for File Name, please install & enable <a href="https://www.drupal.org/project/token" arget="_blank">Token module</a>. <p></p>',
];
}
array_splice($form['file'], 4, 0, [
'filename_token' => $filename_token,
]);
$form['destination'] = [
'#type' => 'fieldset',
"#title" => $this
->t("Destination"),
"#collapsible" => TRUE,
"#collapsed" => FALSE,
"#tree" => FALSE,
];
$form['destination']['destination_id'] = DrupalConfigHelper::getDestinationSelector($bam, $this
->t('Backup Destination'));
$form['destination']['destination_id']['#default_value'] = \Drupal::config('backup_migrate.settings')
->get('backup_migrate_destination_id');
$form['quickbackup']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Backup now'),
'#weight' => 1,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
$bam = backup_migrate_get_service_object($form_state
->getValues());
// Let the plugins validate their own config data.
if ($plugin_errors = $bam
->plugins()
->map('configErrors', [
'operation' => 'backup',
])) {
$has_token_module = \Drupal::moduleHandler()
->moduleExists('token');
foreach ($plugin_errors as $plugin_key => $errors) {
if ($plugin_key == "namer" && isset($errors[0])) {
if ($errors[0]
->getFieldKey() == "filename" && $has_token_module) {
continue;
}
}
foreach ($errors as $error) {
$form_state
->setErrorByName($plugin_key . '][' . $error
->getFieldKey(), $this
->t($error
->getMessage(), $error
->getReplacement()));
}
}
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $form_state
->getValues();
backup_migrate_perform_backup($config['source_id'], $config['destination_id'], $config);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BackupMigrateAdvancedBackupForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
BackupMigrateAdvancedBackupForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
BackupMigrateAdvancedBackupForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
BackupMigrateAdvancedBackupForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
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:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
105 |
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. | |
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. |