Hi all, I would like to use multiple Rules to send emails to al registrants of an event, based on the event date. For example, I would like to send personalized emails after the event with an evaluation link to a Google form with the event title prefilled.
The thing is: I cannot find a way to access the list of registrations instances from the event node. There is a field of type Registration, but I cannot access it using Rules.
What I'd like to do in Rules:
IF event is saved THEN schedule a rule component to be evaluated at (event-end-date + 5 minutes).
The Rule component would then loop through all the Registrants to an event (both anonymous and registered users) and send each one a personalized email.
The problem is I cannot find the list of Registrants to loop through. Is there a way to do this? This would make the module much more flexible for me. I would like to do everything using Rules, since I am a power user but not a maintainer of the website. Using rules gives me much more flexibility in tweaking the emails without having to do a new release of the site. Any help would be much appreciated!

Comments

EdoP created an issue. See original summary.

john.oltman’s picture

Title: Send multiple reminder emails via Rules: cannot access list of registrants » Integrate with Rules module including host entity methods
Version: 7.x-1.3 » 3.0.x-dev
Category: Support request » Feature request
freelock’s picture

Hi,

Not an answer to this request, but a suggestion for an alternative: ECA module. ECA does everything Rules does, and the BPMN modeler even lets you do it visually as a flow chart.

We're using ECA with registration for a lot of tasks like the OP. There is one missing bit: ECA relies upon tokens to make entities available. We needed tokens for the host_entity and the registration settings entity, so we added to a custom module:

function mymodule_token_info_alter(&$data) {
  $data['tokens']['registration']['host_entity'] = [
    'name' => t('Host Entity'),
    'description'=> t('Entity that this is attached to (usually node'),
    'module' => 'mymodule',
    'type' => 'node',
  ];
  $data['tokens']['registration']['settings'] = [
    'name' => t('Registration Settings'),
    'description'=> t('The Registration Settings for the entity this registration is attached to'),
    'module' => 'mymodule',
    'type' => 'registration_settings',
  ];
}

function mymodule_tokens_alter(&$replacements, $context, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata ){
  if ($context['type'] == 'registration'){
    $tokens = $context['tokens'];
    foreach($tokens as $name => $original){
      if(strpos($name, 'host_entity') === 0){
        $field_tokens = \Drupal::token()->findWithPrefix($tokens, 'node');
        $node = $context['data']['registration']->getHostEntity()->getEntity();
        if ($name =='host_entity'){
          $replacements[$original]= $node -> id();
        } else {
          $replacements += \Drupal::token()->generate('node', $field_tokens, ['node'=> $node ], $context['options'], $bubbleable_metadata);
        }
      }
      if(strpos($name, 'settings') === 0){
        $field_tokens = \Drupal::token()->findWithPrefix($tokens, 'settings');
        $registration_settings = $context['data']['registration']->getHostEntity()->getSettings();
        if($name =='settings'){
          $replacements[$original]= $registration_settings -> id();
        } else {
          $replacements += Drupal::token()->generate('registration_settings', $field_tokens,['registration_settings'=> $registration_settings], $context['options'], $bubbleable_metadata);
        }
      }
      $item = $context;
    }
  }
}
john.oltman’s picture

Thanks @freelock, I also prefer ECA over Rules. I may add a new Feature Request for full ECA integration.

Here it is: https://www.drupal.org/project/registration/issues/3378873

Please add any additional ECA thoughts on that issue - thank you!