function drush_node_revision_delete_nrd_when_to_delete_time in Node Revision Delete 8
Same name and namespace in other branches
- 7.3 node_revision_delete.drush.inc \drush_node_revision_delete_nrd_when_to_delete_time()
Callback for the nrd-when-to-delete-time command.
File
- ./
node_revision_delete.drush.inc, line 335 - Drush commands related to the Node Revision Delete module.
Code
function drush_node_revision_delete_nrd_when_to_delete_time() {
$args = func_get_args();
// Getting an editable config because we will get and set a value.
$config = \Drupal::service('config.factory')
->getEditable('node_revision_delete.settings');
// Getting or setting values?
if (isset($args[0])) {
// Saving the values in the config.
$node_revision_delete_when_to_delete_time['max_number'] = $args[0];
$node_revision_delete_when_to_delete_time['time'] = $args[1];
$config
->set('node_revision_delete_when_to_delete_time', $node_revision_delete_when_to_delete_time);
$config
->save();
// We need to update the max_number in the existing content type
// configuration if the new value is lower than the actual.
\Drupal::service('node_revision_delete')
->updateTimeMaxNumberConfig('when_to_delete', $args[0]);
$time = \Drupal::service('node_revision_delete')
->getTimeNumberString($args[0], $args[1]);
$message = dt('The maximum inactivity time was set to @max_number @time.', [
'@max_number' => $args[0],
'@time' => $time,
]);
drush_log($message, 'success');
}
else {
// Getting the values from the config.
$node_revision_delete_when_to_delete_time = $config
->get('node_revision_delete_when_to_delete_time');
$max_number = $node_revision_delete_when_to_delete_time['max_number'];
$time = $node_revision_delete_when_to_delete_time['time'];
$time = \Drupal::service('node_revision_delete')
->getTimeNumberString($max_number, $time);
$message = dt('The maximum inactivity time is: @max_number @time.', [
'@max_number' => $max_number,
'@time' => $time,
]);
drush_print($message);
}
}