You are here

public function NodeRevisionDeleteCommands::minimumAgeToDeleteTime in Node Revision Delete 8

Configures time options to know the minimum age.

Configures time options to know the minimum age. that the revision must have to be delete.

@usage nrd-minimum-age-to-delete-time Shows the time configuration for the minimum age of revisions. @usage nrd-minimum-age-to-delete-time 30 days Set the maximum time for the minimum age to 30 days. @usage nrd-minimum-age-to-delete-time 6 weeks Set the maximum time for the minimum age to 6 weeks.

@command nrd:minimum-age-to-delete-time @aliases nrd-matdt, nrd-minimum-age-to-delete-time

Parameters

int $max_number: The maximum number for minimum age configuration.

int $time: The time value for minimum age configuration (days, weeks or months).

File

src/Commands/NodeRevisionDeleteCommands.php, line 310

Class

NodeRevisionDeleteCommands
Class NodeRevisionDeleteCommands.

Namespace

Drupal\node_revision_delete\Commands

Code

public function minimumAgeToDeleteTime($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_minimum_age_to_delete_time['max_number'] = $max_number;
    $node_revision_delete_minimum_age_to_delete_time['time'] = $time;
    $config
      ->set('node_revision_delete_minimum_age_to_delete_time', $node_revision_delete_minimum_age_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('minimum_age_to_delete', $max_number);

    // Is singular or plural?
    $time = $this->nodeRevisionDelete
      ->getTimeNumberString($max_number, $time);
    $message = dt('<info>The maximum time for the minimum age 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_minimum_age_to_delete_time = $config
      ->get('node_revision_delete_minimum_age_to_delete_time');
    $max_number = $node_revision_delete_minimum_age_to_delete_time['max_number'];
    $time = $node_revision_delete_minimum_age_to_delete_time['time'];

    // Is singular or plural?
    $time = $this->nodeRevisionDelete
      ->getTimeNumberString($max_number, $time);
    $message = dt('<info>The maximum time for the minimum age is: @max_number @time.</info>', [
      '@max_number' => $max_number,
      '@time' => $time,
    ]);
    $this
      ->writeln($message);
  }
}