function RulesCommands::delete

Deletes a rule on your site.

@command rules:delete @interact-rule-names @aliases rdel,rules-delete

@usage drush rules:delete Displays all rules and allows you to select one to delete. @usage drush rules:delete test_rule Permanently deletes the rule with machine name 'test_rule'.

Parameters

string $rule: Rule name (machine id) to delete.

Throws

\Exception

File

src/Commands/RulesCommands.php, line 236

Class

RulesCommands
Drush 9+ commands for the Rules module.

Namespace

Drupal\rules\Commands

Code

public function delete($rule) {
    // The $rule argument could refer to a Reaction Rule or a Rules Component.
    if ($this->configStorage
        ->exists('rules.reaction.' . $rule)) {
        $config = $this->configFactory
            ->getEditable('rules.reaction.' . $rule);
    }
    elseif ($this->configStorage
        ->exists('rules.component.' . $rule)) {
        $config = $this->configFactory
            ->getEditable('rules.component.' . $rule);
    }
    elseif ($this->configStorage
        ->exists($rule)) {
        $config = $this->configFactory
            ->getEditable($rule);
    }
    else {
        throw new \Exception(dt('Could not find a Reaction Rule or a Rules Component named @name', [
            '@name' => $rule,
        ]));
    }
    if ($this->confirm(dt('Are you sure you want to delete the rule named "@name"? This action cannot be undone.', [
        '@name' => $rule,
    ]))) {
        $config->delete();
        $this->logger
            ->success(dt('The rule @name has been deleted.', [
            '@name' => $rule,
        ]));
    }
}