You are here

public function RulesCommands::export in Rules 8.3

Exports a single rule configuration, in YAML format.

@command rules:export @aliases rexp,rules-export

@codingStandardsIgnoreStart @usage drush rules:export test_rule > rules.reaction.test_rule.yml Exports the Rule with machine name 'test_rule' and saves it in a .yml file. @usage drush rules:list --pipe --type=component | xargs -I{} sh -c "drush rules:export '{}' > 'rules.component.{}.yml'" Exports all Rules Components into individual YAML files. @codingStandardsIgnoreEnd

Parameters

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

Throws

\Exception

File

src/Commands/RulesCommands.php, line 254

Class

RulesCommands
Drush 9+ commands for the Rules module.

Namespace

Drupal\rules\Commands

Code

public function export($rule) {

  // The $rule argument could refer to a Reaction Rule or a Rules Component.
  $config = $this->configStorage
    ->read('rules.reaction.' . $rule);
  if (empty($config)) {
    $config = $this->configStorage
      ->read('rules.component.' . $rule);
    if (empty($config)) {
      throw new \Exception(dt('Could not find a Reaction Rule or a Rules Component named @name', [
        '@name' => $rule,
      ]));
    }
  }
  $this->output
    ->write(Yaml::encode($config), FALSE);
  $this->logger
    ->success(dt('The rule @name has been exported.', [
    '@name' => $rule,
  ]));
}