You are here

public function DrupalFilesSourcePlugin::alterBackupMigrate in Backup and Migrate 8.4

Same name and namespace in other branches
  1. 5.0.x src/Plugin/BackupMigrateSource/DrupalFilesSourcePlugin.php \Drupal\backup_migrate\Plugin\BackupMigrateSource\DrupalFilesSourcePlugin::alterBackupMigrate()

Alter the backup and migrate object to add the source and required services.

Parameters

\BackupMigrate\Core\Main\BackupMigrateInterface $bam: The BackupMigrate object to add plugins and services to.

$key: The id of the source to add.

array $options: The alter options.

Return value

mixed

Overrides SourcePluginBase::alterBackupMigrate

See also

hook_backup_migrate_service_object_alter()

File

src/Plugin/BackupMigrateSource/DrupalFilesSourcePlugin.php, line 34

Class

DrupalFilesSourcePlugin
Defines an default database source plugin.

Namespace

Drupal\backup_migrate\Plugin\BackupMigrateSource

Code

public function alterBackupMigrate(BackupMigrateInterface $bam, $key, $options = []) {
  $source = $this
    ->getObject();
  $bam
    ->sources()
    ->add($key, $source);
  $config = [
    'exclude_filepaths' => [],
    'source' => $source,
  ];
  switch ($this
    ->getConfig()
    ->get('directory')) {
    case 'public://':
      $config['exclude_filepaths'] = [
        'js',
        'css',
        'php',
        'styles',
        'config_*',
        '.htaccess',
      ];
      break;
    case 'private://':
      $config['exclude_filepaths'] = [
        'backup_migrate',
      ];
      break;
  }

  // @TODO: Allow modules to add their own excluded defaults.
  $bam
    ->plugins()
    ->add($key . '_exclude', new FileExcludeFilter(new Config($config)));
}