function RulesCommands::disable
Disables a Reaction Rule on your site.
@command rules:disable @interact-enabled-rules @aliases rdis,rules-disable
@usage drush rules:disable Displays all enabled rules and allows you to select one to disable. @usage drush rules:disable test_rule Disables the rule with machine name 'test_rule'.
Parameters
string $rule: Reaction rule name (machine name) to disable.
Throws
\Exception
File
-
src/
Commands/ RulesCommands.php, line 196
Class
- RulesCommands
- Drush 9+ commands for the Rules module.
Namespace
Drupal\rules\CommandsCode
public function disable($rule) {
// The $rule argument must be a Reaction Rule.
if ($this->configStorage
->exists('rules.reaction.' . $rule)) {
$config = $this->configFactory
->getEditable('rules.reaction.' . $rule);
}
elseif ($this->configStorage
->exists($rule)) {
$config = $this->configFactory
->getEditable($rule);
}
else {
throw new \Exception(dt('Could not find a Reaction Rule named @name', [
'@name' => $rule,
]));
}
if ($config->get('status')) {
$config->set('status', FALSE);
$config->save();
$this->logger
->success(dt('The rule @name has been disabled.', [
'@name' => $rule,
]));
}
else {
$this->logger
->warning(dt('The rule @name is already disabled', [
'@name' => $rule,
]));
}
}