public function NodeRevisionDeleteCommands::whenToDeleteTime in Node Revision Delete 8
Configures the time options for the inactivity time.
Configures the time options for the inactivity time that the revision must have to be deleted.
@usage nrd-when-to-delete-time Shows the time configuration for the inactivity time. @usage nrd-when-to-delete-time 30 days Set the maximum inactivity time to 30 days. @usage nrd-when-to-delete-time 6 weeks Set the maximum inactivity time to 6 weeks.
@command nrd:when-to-delete-time @aliases nrd-wtdt, nrd-when-to-delete-time
Parameters
int $max_number: The maximum number for inactivity time configuration.
int $time: The time value for inactivity time configuration (days, weeks or months).
File
- src/
Commands/ NodeRevisionDeleteCommands.php, line 258
Class
- NodeRevisionDeleteCommands
- Class NodeRevisionDeleteCommands.
Namespace
Drupal\node_revision_delete\CommandsCode
public function whenToDeleteTime($max_number = NULL, $time = NULL) {
// Getting an editable config because we will get and set a value.
$config = $this->configFactory
->getEditable('node_revision_delete.settings');
// Getting or setting values?
if (isset($max_number)) {
// Saving the values in the config.
$node_revision_delete_when_to_delete_time['max_number'] = $max_number;
$node_revision_delete_when_to_delete_time['time'] = $time;
$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.
$this->nodeRevisionDelete
->updateTimeMaxNumberConfig('when_to_delete', $max_number);
$time = $this->nodeRevisionDelete
->getTimeNumberString($max_number, $time);
$message = dt('<info>The maximum inactivity time was set to @max_number @time.</info>', [
'@max_number' => $max_number,
'@time' => $time,
]);
$this
->writeln($message);
}
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 = $this->nodeRevisionDelete
->getTimeNumberString($max_number, $time);
$message = dt('<info>The maximum inactivity time is: @max_number @time.</info>', [
'@max_number' => $max_number,
'@time' => $time,
]);
$this
->writeln($message);
}
}