You are here

public static function EventTypeForm::createDefaultRules in RNG - Events and Registrations 3.x

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

Create default rules for an event type.

Parameters

$entity_type_id: An entity type ID.

$bundle: A bundle ID.

3 calls to EventTypeForm::createDefaultRules()
EventTypeForm::save in src/Form/EventTypeForm.php
Form submission handler for the 'save' action.
RngEventAccessWebTest::setUp in tests/src/Functional/RngEventAccessWebTest.php
RngSiteTestBase::setUp in src/Tests/RngSiteTestBase.php

File

src/Form/EventTypeForm.php, line 459

Class

EventTypeForm
Form controller for event config entities.

Namespace

Drupal\rng\Form

Code

public static function createDefaultRules($entity_type_id, $bundle) {

  // User Role.

  /** @var \Drupal\rng\Entity\EventTypeRuleInterface $rule */
  $rule = EventTypeRule::create([
    'trigger' => 'rng_event.register',
    'entity_type' => $entity_type_id,
    'bundle' => $bundle,
    'machine_name' => 'user_role',
  ]);
  $rule
    ->setCondition('role', [
    'id' => 'rng_user_role',
    'roles' => [],
  ]);
  $rule
    ->setAction('registration_operations', [
    'id' => 'registration_operations',
    'configuration' => [
      'operations' => [
        'create' => TRUE,
      ],
    ],
  ]);
  $rule
    ->save();

  // Registrant.
  $rule = EventTypeRule::create([
    'trigger' => 'rng_event.register',
    'entity_type' => $entity_type_id,
    'bundle' => $bundle,
    'machine_name' => 'registrant',
  ]);
  $rule
    ->setCondition('identity', [
    'id' => 'rng_registration_identity',
  ]);
  $rule
    ->setAction('registration_operations', [
    'id' => 'registration_operations',
    'configuration' => [
      'operations' => [
        'view' => TRUE,
        'update' => TRUE,
      ],
    ],
  ]);
  $rule
    ->save();

  // Event managers.
  $rule = EventTypeRule::create([
    'trigger' => 'rng_event.register',
    'entity_type' => $entity_type_id,
    'bundle' => $bundle,
    'machine_name' => 'event_manager',
  ]);
  $rule
    ->setCondition('operation', [
    'id' => 'rng_event_operation',
    'operations' => [
      'manage event' => TRUE,
    ],
  ]);
  $rule
    ->setAction('registration_operations', [
    'id' => 'registration_operations',
    'configuration' => [
      'operations' => [
        'create' => TRUE,
        'view' => TRUE,
        'update' => TRUE,
        'delete' => TRUE,
      ],
    ],
  ]);
  $rule
    ->save();
}