public static function Settings::set in Hook Update Deploy Tools 8
Same name and namespace in other branches
- 7 src/Settings.php \HookUpdateDeployTools\Settings::set()
Sets a Drupal variable but adds testing loop and feedback.
Parameters
string $name: The name of the variable to set.
mixed $value: The value to set. This can be any PHP data type; variable_set takes care of serialization as necessary.
Return value
string Message to report through hook_update_N.
File
- src/
Settings.php, line 21
Class
- Settings
- Public methods for altering Settings.
Namespace
HookUpdateDeployToolsCode
public static function set($name, $value) {
$original_value = variable_get($name, 'not set');
if ($value === $original_value || is_object($value) && is_object($original_value) && $value == $original_value) {
// There is no requested change. Skip making a change.
$msg_vars = array(
'!name' => $name,
'!value' => $value,
);
$message = "The variable '!name' is already set to '!value'. Skipped variable_set.";
$result = Message::make($message, $msg_vars, WATCHDOG_INFO, 1);
}
else {
// Go ahead and make the set.
variable_set($name, $value);
$result = self::confirmSet($name, $value, $original_value);
}
return $result;
}