You are here

function business_rules_entity_load in Business Rules 8

Same name and namespace in other branches
  1. 2.x business_rules.module \business_rules_entity_load()

Implements hook_entity_load().

File

./business_rules.module, line 320
Business Rules module.

Code

function business_rules_entity_load(array $entities, $entity_type_id) {
  foreach ($entities as $entity) {
    if (\Drupal::service('business_rules.processor')
      ->ruleExists('entity_is_loaded', $entity)) {
      $reacts_on_definition = \Drupal::getContainer()
        ->get('plugin.manager.business_rules.reacts_on')
        ->getDefinition('entity_is_loaded');
      $entity_type_id = $entity
        ->getEntityTypeId();
      $event = new BusinessRulesEvent($entity, [
        'entity_type_id' => $entity_type_id,
        'bundle' => $entity
          ->bundle(),
        'entity' => $entity,
        'entity_unchanged' => $entity->original,
        'reacts_on' => $reacts_on_definition,
        'loop_control' => $entity
          ->getEntityTypeId() . $entity
          ->id(),
      ]);

      /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher */
      $event_dispatcher = \Drupal::service('event_dispatcher');
      $event_dispatcher
        ->dispatch($reacts_on_definition['eventName'], $event);
    }
  }
}