You are here

function _scheduler_rules_integration_event in Scheduler 2.x

Dispatch a Rules Integration event for an entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity object being processed.

string $event_id: The internal event id, for example NEW_FOR_PUBLISHING or CRON_PUBLISHED.

3 calls to _scheduler_rules_integration_event()
scheduler_rules_integration_entity_insert in scheduler_rules_integration/scheduler_rules_integration.module
Implements hook_entity_insert().
scheduler_rules_integration_entity_update in scheduler_rules_integration/scheduler_rules_integration.module
Implements hook_entity_update().
_scheduler_rules_integration_dispatch_cron_event in scheduler_rules_integration/scheduler_rules_integration.module
Trigger Rules events during cron.

File

scheduler_rules_integration/scheduler_rules_integration.module, line 23
Scheduler Rules Integration.

Code

function _scheduler_rules_integration_event(EntityInterface $entity, $event_id) {

  // Derive the fully namespaced event class for the given type of entity. The
  // entity type id may contain underscores and these need to be converted to
  // camelCase to match the event class. For example the class for 'node' is
  // simply RulesNodeEvent, but the class for commerce_product is
  // RulesCommerceProductEvent.
  $camelCaseEntityType = str_replace(' ', '', ucwords(str_replace('_', ' ', $entity
    ->getEntityTypeId())));
  $event_class = "\\Drupal\\scheduler_rules_integration\\Event\\Rules{$camelCaseEntityType}Event";
  $event = new $event_class($entity);
  $event_name = constant(get_class($event) . "::{$event_id}");
  \Drupal::service('scheduler.manager')
    ->dispatch($event, $event_name);
}