function RulesCommands::enable
Enables a Reaction Rule on your site.
@command rules:enable @interact-disabled-rules @aliases renb,rules-enable
@usage drush rules:enable Displays all disabled rules and allows you to select one to enable. @usage drush rules:enable test_rule Enables the rule with machine name 'test_rule'.
Parameters
string $rule: Reaction rule name (machine name) to enable.
Throws
\Exception
File
-
src/
Commands/ RulesCommands.php, line 156
Class
- RulesCommands
- Drush 9+ commands for the Rules module.
Namespace
Drupal\rules\CommandsCode
public function enable($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', TRUE);
$config->save();
$this->logger
->success(dt('The rule @name has been enabled.', [
'@name' => $rule,
]));
}
else {
$this->logger
->warning(dt('The rule @name is already enabled', [
'@name' => $rule,
]));
}
}