function backup_migrate_backup_migrate_service_object_alter in Backup and Migrate 8.4
Same name and namespace in other branches
- 5.0.x backup_migrate.module \backup_migrate_backup_migrate_service_object_alter()
Implements hook_backup_migrate_service_object_alter().
Add the core Backup and Migrate plugins to the service object.
Parameters
\BackupMigrate\Core\Main\BackupMigrateInterface $bam:
array $options:
File
- ./
backup_migrate.module, line 115 - Primary hook implementations for Backup Migrate.
Code
function backup_migrate_backup_migrate_service_object_alter(BackupMigrateInterface &$bam, $options = []) {
$sources = $bam
->sources();
$destinations = $bam
->destinations();
$plugins = $bam
->plugins();
$services = $bam
->services();
// Add a temp file manager which can access the drupal temp directory.
$services
->add('TempFileAdapter', new \BackupMigrate\Drupal\File\DrupalTempFileAdapter(\Drupal::service('file_system'), 'temporary://', 'bam'));
$services
->add('TempFileManager', new \BackupMigrate\Core\File\TempFileManager($services
->get('TempFileAdapter')));
// Add a logger which prints everything to the browser.
$services
->add('Logger', new \BackupMigrate\Drupal\Environment\DrupalSetMessageLogger());
$services
->add('ArchiveReader', new \BackupMigrate\Core\Service\TarArchiveReader());
$services
->add('ArchiveWriter', new \BackupMigrate\Core\Service\TarArchiveWriter());
// If this is a nobrowser op (cron) then do not add the browser plugins.
// TODO: Make this better.
if (empty($options['nobrowser'])) {
// Add a download destination.
$user = \Drupal::currentUser();
if ($user
->hasPermission('access backup files')) {
$destinations
->add('download', new \BackupMigrate\Drupal\Destination\DrupalBrowserDownloadDestination(new Config([
'name' => t('Download'),
])));
}
// Add an upload destination.
$destinations
->add('upload', new \BackupMigrate\Drupal\Destination\DrupalBrowserUploadDestination(new Config([
'name' => t('Upload'),
])));
}
// Add a file naming filter.
$plugins
->add('namer', new \BackupMigrate\Core\Filter\FileNamer());
// Add a compression filter.
$plugins
->add('compressor', new \BackupMigrate\Core\Filter\CompressionFilter());
// Add the Encrypt utilities filter.
$plugins
->add('encrypt', new \BackupMigrate\Drupal\Filter\DrupalEncrypt());
// Add the Drupal utilities filter.
$plugins
->add('utils', new \BackupMigrate\Drupal\Filter\DrupalUtils());
// Add a file metadata filter.
$plugins
->add('metadata', new \BackupMigrate\Core\Filter\MetadataWriter(new Config([
'generator' => 'Backup and Migrate for Drupal (https://www.drupal.org/project/backup_migrate)',
'generatorurl' => 'https://www.drupal.org/project/backup_migrate',
'generatorversion' => BACKUP_MIGRATE_MODULE_VERSION,
])));
// Add the custom configured sources.
foreach (Source::loadMultiple() as $source) {
$source
->getPlugin()
->alterBackupMigrate($bam, $source
->get('id'), $options);
}
// Add the custom configured destination.
foreach (Destination::loadMultiple() as $destination) {
$destination
->getPlugin()
->alterBackupMigrate($bam, $destination
->get('id'), $options);
}
}