function demo_get_config_dumps in Demonstration site (Sandbox / Snapshot) 8
2 calls to demo_get_config_dumps()
- DeleteConfigForm::buildForm in src/
Form/ DeleteConfigForm.php - form to delete config snapshots.
- DemoConfigResetConfirm::buildForm in src/
Form/ DemoConfigResetConfirm.php - Form constructor.
File
- ./
demo.module, line 932
Code
function demo_get_config_dumps() {
$fileconfig = demo_get_fileconfig();
// Fetch list of available info files.
$files = \Drupal::service('file_system')
->scanDirectory($fileconfig['dumppath'], '/\\.tar.gz$/');
foreach ($files as $file => $object) {
$files[$file]->filemtime = filemtime($file);
$files[$file]->filesize = filesize(substr($file, 0, -7) . '.tar.gz');
}
// Sort snapshots by date (ascending file modification time).
uasort($files, function ($a, $b) {
return $a->filemtime < $b->filemtime;
});
$element = [
'#type' => 'radios',
'#title' => t('Snapshot'),
'#required' => TRUE,
'#parents' => [
'filename',
],
'#options' => [],
'#attributes' => [
'class' => [
'demo-snapshots-widget',
],
],
'#attached' => [
'library' => [
'demo/demo-library',
],
],
];
foreach ($files as $filename => $file) {
// Prepare snapshot title.
$title = t('@snapshot <small>(@date, @aize)</small>', [
'@snapshot' => substr($filename, 15),
'@date' => \Drupal::service('date.formatter')
->format($file->filemtime, 'small'),
'@aize' => format_size($file->filesize),
]);
// Add the radio option element.
$element['#options'][$filename] = $title;
$element[$filename] = [
'#file' => $file,
];
}
return $element;
}