You are here

public function EventMeta::getDefaultRules in RNG - Events and Registrations 3.x

Same name and namespace in other branches
  1. 8.2 src/EventMeta.php \Drupal\rng\EventMeta::getDefaultRules()
  2. 8 src/EventMeta.php \Drupal\rng\EventMeta::getDefaultRules()

Gets site default access rules and associated conditions and actions.

Parameters

string $trigger: The trigger ID for the rules.

Return value

\Drupal\rng\Entity\RuleInterface[] An array of rng_rule entities.

Overrides EventMetaInterface::getDefaultRules

2 calls to EventMeta::getDefaultRules()
EventMeta::addDefaultAccess in src/EventMeta.php
Clones the site default access rules onto the event.
EventMeta::getRules in src/EventMeta.php
Get all rules for this event.

File

src/EventMeta.php, line 374

Class

EventMeta
Meta event wrapper for RNG.

Namespace

Drupal\rng

Code

public function getDefaultRules($trigger = NULL) {
  $rules = [];
  if ($trigger != 'rng_event.register') {
    return $rules;
  }

  /** @var \Drupal\rng\Entity\EventTypeRuleInterface[] $default_rules */
  $default_rules = $this->entityManager
    ->getStorage('rng_event_type_rule')
    ->loadByProperties([
    'entity_type' => $this
      ->getEvent()
      ->getEntityTypeId(),
    'bundle' => $this
      ->getEvent()
      ->bundle(),
    'trigger' => $trigger,
  ]);
  foreach ($default_rules as $default_rule) {
    $rule = Rule::create([
      'event' => [
        'entity' => $this
          ->getEvent(),
      ],
      'trigger_id' => $trigger,
      'status' => TRUE,
    ]);
    foreach ($default_rule
      ->getConditions() as $condition) {
      $plugin_id = $condition['id'];
      unset($condition['id']);
      $component = RuleComponent::create()
        ->setType('condition')
        ->setPluginId($plugin_id)
        ->setConfiguration($condition);
      $rule
        ->addComponent($component);
    }
    foreach ($default_rule
      ->getActions() as $action) {
      $component = RuleComponent::create()
        ->setType('action')
        ->setPluginId($action['id'])
        ->setConfiguration($action['configuration']);
      $rule
        ->addComponent($component);
    }
    $rules[] = $rule;
  }
  return $rules;
}