Updates 7.x variables to state records.
Provides a generalized method to migrate variables from 7.x to 8.x's Drupal::state() system.
array $variable_map: An associative array that maps old variables names to new state record names; e.g.:
array(
'old_variable' => 'extension.new_name',
);
This would migrate the value contained in variable name 'old_variable' into the state item 'extension.new_name'. Non-existing variables and variables with NULL values are omitted.
function update_variables_to_state(array $variable_map) {
foreach ($variable_map as $variable_name => $state_name) {
if (NULL !== ($value = update_variable_get($variable_name))) {
Drupal::state()
->set($state_name, $value);
}
}
// Delete the migrated variables.
db_delete('variable')
->condition('name', array_keys($variable_map))
->execute();
}