class FileNamer in Backup and Migrate 5.0.x
@package Drupal\backup_migrate\Core\Filter
Hierarchy
- class \Drupal\backup_migrate\Core\Plugin\PluginBase implements ConfigurableInterface, PluginInterface uses ConfigurableTrait
- class \Drupal\backup_migrate\Core\Filter\FileNamer implements FileProcessorInterface uses FileProcessorTrait
Expanded class hierarchy of FileNamer
1 file declares its use of FileNamer
- backup_migrate.module in ./
backup_migrate.module - Primary hook implementations for Backup Migrate.
File
- src/
Core/ Filter/ FileNamer.php, line 16
Namespace
Drupal\backup_migrate\Core\FilterView source
class FileNamer extends PluginBase implements FileProcessorInterface {
use FileProcessorTrait;
/**
* {@inheritdoc}
*/
public function configSchema(array $params = []) {
$schema = [];
if (\Drupal::moduleHandler()
->moduleExists('token')) {
$must_match = '/^[\\w\\-_:\\[\\]]+$/';
$must_match_err = $this
->t('%title must contain only letters, numbers, dashes (-) and underscores (_). And Site Tokens.');
}
else {
$must_match = '/^[\\w\\-_:]+$/';
$must_match_err = $this
->t('%title must contain only letters, numbers, dashes (-) and underscores (_).');
}
// Backup configuration.
if ($params['operation'] == 'backup') {
$schema['groups']['file'] = [
'title' => 'Backup File',
];
$schema['fields']['filename'] = [
'group' => 'file',
'type' => 'text',
'title' => 'File Name',
'must_match' => $must_match,
'must_match_error' => $must_match_err,
'min_length' => 1,
// Allow a 200 character backup name leaving a generous 55 characters
// for timestamp and extension.
'max_length' => 200,
'required' => TRUE,
];
$schema['fields']['timestamp'] = [
'group' => 'file',
'type' => 'boolean',
'title' => 'Append a timestamp',
];
$schema['fields']['timestamp_format'] = [
'group' => 'file',
'type' => 'text',
'title' => 'Timestamp Format',
'max_length' => 32,
'dependencies' => [
'timestamp' => TRUE,
],
'description' => $this
->t('Use <a href="http://php.net/date">PHP Date formatting</a>.'),
];
}
return $schema;
}
/**
* Get the default values for the plugin.
*
* @return \Drupal\backup_migrate\Core\Config\Config
*/
public function configDefaults() {
return new Config([
'filename' => 'backup',
'timestamp' => TRUE,
'timestamp_format' => 'Y-m-d\\TH-i-s',
]);
}
/**
* Get a list of supported operations and their weight.
*
* @return array
*/
public function supportedOps() {
return [
'afterBackup' => [],
];
}
/**
* Run on a backup. Name the backup file according to the configuration.
*
* @param \Drupal\backup_migrate\Core\File\BackupFileReadableInterface $file
*
* @return \Drupal\backup_migrate\Core\File\BackupFileReadableInterface
*/
public function afterBackup(BackupFileReadableInterface $file) {
if (\Drupal::moduleHandler()
->moduleExists('token')) {
$token = \Drupal::token();
$name = $token
->replace($this
->confGet('filename'));
}
else {
$name = $this
->confGet('filename');
}
if ($this
->confGet('timestamp')) {
$name .= '-' . date($this
->confGet('timestamp_format'));
}
$file
->setName($name);
return $file;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigurableTrait:: |
protected | property | The object's configuration object. | |
ConfigurableTrait:: |
protected | property | The initial configuration. | |
ConfigurableTrait:: |
public | function | Get a specific value from the configuration. | |
ConfigurableTrait:: |
public | function | Get the configuration object for this item. | |
ConfigurableTrait:: |
public | function | Get any validation errors in the config. | |
ConfigurableTrait:: |
public | function | Set the configuration for all plugins. | 1 |
ConfigurableTrait:: |
public | function | 2 | |
FileNamer:: |
public | function | Run on a backup. Name the backup file according to the configuration. | |
FileNamer:: |
public | function |
Get the default values for the plugin. Overrides ConfigurableTrait:: |
|
FileNamer:: |
public | function |
Get a default (blank) schema. Overrides ConfigurableTrait:: |
|
FileNamer:: |
public | function |
Get a list of supported operations and their weight. Overrides PluginBase:: |
|
FileProcessorTrait:: |
protected | property | ||
FileProcessorTrait:: |
public | function | Provide the file mime for the given file extension if known. | |
FileProcessorTrait:: |
public | function | Get the temp file manager. | |
FileProcessorTrait:: |
public | function | Inject the temp file manager. | |
PluginBase:: |
public | function |
What is the weight of the given operation for this plugin. Overrides PluginInterface:: |
|
PluginBase:: |
public | function |
Does this plugin implement the given operation. Overrides PluginInterface:: |
|
TranslatableTrait:: |
protected | property | ||
TranslatableTrait:: |
public | function | ||
TranslatableTrait:: |
public | function | Translate the given string if there is a translator service available. |