You are here

public function NodeRevisionDelete::updateTimeMaxNumberConfig in Node Revision Delete 8

Update the max_number for a config name.

We need to update the max_number in the existing content type configuration if the new value (max_number) is lower than the actual, in this case the new value will be the value for the content type.

Parameters

string $config_name: Config name to update (when_to_delete or minimum_age_to_delete).

int $max_number: The maximum number for $config_name parameter.

Overrides NodeRevisionDeleteInterface::updateTimeMaxNumberConfig

File

src/NodeRevisionDelete.php, line 89

Class

NodeRevisionDelete
Class NodeRevisionDelete.

Namespace

Drupal\node_revision_delete

Code

public function updateTimeMaxNumberConfig($config_name, $max_number) {

  // Looking for all the configured content types.
  $content_types = $this
    ->getConfiguredContentTypes();

  // Checking the when_to_delete value for all the configured content types.
  foreach ($content_types as $content_type) {

    // Getting the config variables.
    $config = $this->configFactory
      ->getEditable('node.type.' . $content_type
      ->id());
    $third_party_settings = $config
      ->get('third_party_settings');

    // If the new defined max_number is smaller than the defined
    // when_to_delete value in the config, we need to change the stored config
    // value.
    if ($max_number < $third_party_settings['node_revision_delete'][$config_name]) {
      $third_party_settings['node_revision_delete'][$config_name] = $max_number;

      // Saving the values in the config.
      $config
        ->set('third_party_settings', $third_party_settings)
        ->save();
    }
  }
}