예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function getDefaultRules($trigger = NULL)
 {
     $definitions = [];
     if ($trigger == 'rng_event.register') {
         // Allow any user to create a registration on the event.
         $definitions['user_role']['condition']['rng_user_role'] = ['roles' => []];
         $definitions['user_role']['action']['registration_operations'] = ['operations' => ['create' => TRUE]];
         // Allow registrants to edit their registrations.
         $definitions['registrant']['condition']['rng_registration_identity'] = [];
         $definitions['registrant']['action']['registration_operations'] = ['operations' => ['view' => TRUE, 'update' => TRUE]];
         // Give event managers all rights.
         $definitions['event_operation']['condition']['rng_event_operation'] = ['operations' => ['manage event' => TRUE]];
         $definitions['event_operation']['action']['registration_operations'] = ['operations' => ['create' => TRUE, 'view' => TRUE, 'update' => TRUE, 'delete' => TRUE]];
     }
     $rules = [];
     foreach ($definitions as $definition) {
         $rule = Rule::create(['event' => array('entity' => $this->getEvent()), 'trigger_id' => 'rng_event.register', 'status' => TRUE]);
         foreach (['condition', 'action'] as $component_type) {
             if (isset($definition[$component_type])) {
                 foreach ($definition[$component_type] as $plugin_id => $configuration) {
                     $component = RuleComponent::create()->setType($component_type)->setPluginId($plugin_id)->setConfiguration($configuration);
                     $rule->addComponent($component);
                 }
             }
         }
         $rules[] = $rule;
     }
     return $rules;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->actionPlugin->submitConfigurationForm($form, $form_state);
     if (!($template_collection = $this->actionPlugin->getTemplateCollection())) {
         drupal_set_message(t('Unable to create templates.', 'error'));
         return;
     }
     $event = $form_state->get('event');
     $context = $this->entityManager->getStorage('courier_context')->load('rng_registration_' . $event->getEntityTypeId());
     if (!$context) {
         throw new \Exception(sprintf('No context available for %s', $event->getEntityTypeId()));
     }
     $template_collection->setContext($context);
     $template_collection->setOwner($event);
     $template_collection->save();
     drupal_set_message(t('Templates created.'));
     $action = RuleComponent::create([])->setPluginId($this->actionPlugin->getPluginId())->setConfiguration($this->actionPlugin->getConfiguration())->setType('action');
     $trigger_id = $form_state->getValue('trigger');
     $rule = Rule::create(['event' => array('entity' => $event), 'trigger_id' => $trigger_id]);
     $rule->save();
     $action->setRule($rule)->save();
     if ($trigger_id == 'rng:custom:date') {
         $rule_component = RuleComponent::create()->setRule($rule)->setType('condition')->setPluginId('rng_rule_scheduler');
         $rule_component->save();
         // Save the ID into config.
         $rule_component->setConfiguration(['rng_rule_component' => $rule_component->id()]);
         $rule_component->save();
     }
     $entity_type = $event->getEntityTypeId();
     $form_state->setRedirectUrl(Url::fromRoute('rng.event.' . $entity_type . '.messages', [$entity_type => $event->id()]));
 }