Integrate with Rules module including host entity methods

Created on 8 July 2017, almost 7 years ago
Updated 2 August 2023, 11 months ago

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!

✨ Feature request
Status

Active

Version

3.0

Component

Registration Core

Created by

πŸ‡³πŸ‡±Netherlands EdoP

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States john.oltman
  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    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;
        }
      }
    }
    
  • πŸ‡ΊπŸ‡ΈUnited States john.oltman

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

Production build 0.69.0 2024