function RulesCommands::listAll

Lists all the active and inactive rules for your site.

@command rules:list @aliases rlst,rules-list

@usage drush rules:list Lists both Reaction Rules and Rules Components. @usage drush rules:list component Lists only Rules Components. @usage drush rules:list --fields=machine-name Lists just the machine names. @usage drush rules:list --fields=machine-name --pipe Outputs machine names in a format suitable for piping.

@table-style default @field-labels machine-name: Rule label: Label event: Event active: Active @default-fields machine-name,label,event,active

Parameters

string $type: (optional) Either 'rule' or 'component'. Any other value (or no value) will list both Reaction Rules and Rules Components.

array $options: (optional) The options.

Return value

\Consolidation\OutputFormatters\StructuredData\RowsOfFields The data.

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

src/Commands/RulesCommands.php, line 91

Class

RulesCommands
Drush 9+ commands for the Rules module.

Namespace

Drupal\rules\Commands

Code

public function listAll($type = '', array $options = [
    'format' => 'table',
    'fields' => '',
]) {
    // Type is 'rule', or 'component'. Any other value (or no value) will
    // list both Reaction Rules and Rules Components.
    switch ($type) {
        case 'rule':
            $types = [
                'reaction',
            ];
            break;
        case 'component':
            $types = [
                'component',
            ];
            break;
        default:
            $types = [
                'reaction',
                'component',
            ];
            break;
    }
    // Loop over type parameter.
    $rows = [];
    foreach ($types as $item) {
        $rules = $this->configFactory
            ->listAll('rules.' . $item);
        // Loop over configuration entities for this $item.
        foreach ($rules as $config) {
            $rule = $this->configFactory
                ->get($config);
            if (!empty($rule->get('id')) && !empty($rule->get('label'))) {
                $events = [];
                $active = '';
                // Components don't have events and can't be enabled/disabled.
                if ($item == 'reaction') {
                    foreach ($rule->get('events') as $event) {
                        $plugin = $this->rulesEventManager
                            ->getDefinition($event['event_name']);
                        $events[] = (string) $plugin['label'];
                    }
                    $active = $rule->get('status') ? dt('Enabled') : dt('Disabled');
                }
                $rows[(string) $rule->get('id')] = [
                    'machine-name' => (string) $rule->get('id'),
                    'label' => (string) $rule->get('label'),
                    'event' => implode(', ', $events),
                    'active' => (string) $active,
                ];
            }
        }
    }
    return new RowsOfFields($rows);
}