function demo_set_info in Demonstration site (Sandbox / Snapshot) 8
Same name and namespace in other branches
- 5 demo.admin.inc \demo_set_info()
- 6 demo.admin.inc \demo_set_info()
- 7 demo.admin.inc \demo_set_info()
1 call to demo_set_info()
- _demo_dump in ./
demo.module - Create a new snapshot.
File
- ./
demo.module, line 599
Code
function demo_set_info($values = NULL) {
if (isset($values['filename']) && is_array($values)) {
// Check for valid filename.
if (!preg_match('/^[-_\\.a-zA-Z0-9]+$/', $values['filename'])) {
\Drupal::messenger()
->addError(t('Invalid filename. It must only contain alphanumeric characters, dots, dashes and underscores. Other characters, including spaces, are not allowed.'));
return FALSE;
}
if (!empty($values['description'])) {
// parse_ini_file() doesn't allow certain characters in description.
$s = [
"\r\n",
"\r",
"\n",
'"',
];
$r = [
' ',
' ',
' ',
"'",
];
$values['description'] = str_replace($s, $r, $values['description']);
}
else {
// If new description is empty, try to use previous description.
$old_file = demo_get_fileconfig($values['filename']);
$old_description = demo_get_info($old_file['infofile'], 'description');
if (!empty($old_description)) {
$values['description'] = $old_description;
}
}
// Set values.
$infos = [];
$infos['filename'] = $values['filename'];
$infos['description'] = '"' . $values['description'] . '"';
$infos['modules'] = implode(' ', getModuleNames());
$infos['version'] = DEMO_DUMP_VERSION;
// Write information to .info file.
$fileconfig = demo_get_fileconfig($values['filename']);
$infofile = fopen($fileconfig['infofile'], 'w');
foreach ($infos as $key => $info) {
fwrite($infofile, $key . ' = ' . $info . "\n");
}
fclose($infofile);
return $infos;
}
}