diff -u b/business_rules.module b/business_rules.module --- b/business_rules.module +++ b/business_rules.module @@ -7,7 +7,6 @@ use Drupal\business_rules\Entity\Schedule; use Drupal\business_rules\Events\BusinessRulesEvent; -use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\Display\EntityFormDisplayInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityFormInterface; @@ -44,7 +43,7 @@ */ function business_rules_entity_presave(EntityInterface $entity) { // Only handle content entities and ignore config entities. - if ($entity instanceof ContentEntityInterface && \Drupal::service('business_rules.processor')->businessRulesExists('entity_presave', $entity)) { + if (\Drupal::service('business_rules.processor')->ruleExists('entity_presave', $entity)) { $reacts_on_definition = \Drupal::getContainer() ->get('plugin.manager.business_rules.reacts_on') ->getDefinition('entity_presave'); @@ -70,7 +69,7 @@ */ function business_rules_entity_update(EntityInterface $entity) { // Only handle content entities and ignore config entities. - if ($entity instanceof ContentEntityInterface && \Drupal::service('business_rules.processor')->businessRulesExists('entity_update', $entity)) { + if (\Drupal::service('business_rules.processor')->ruleExists('entity_update', $entity)) { $reacts_on_definition = \Drupal::getContainer() ->get('plugin.manager.business_rules.reacts_on') ->getDefinition('entity_update'); @@ -95,7 +94,7 @@ */ function business_rules_entity_insert(EntityInterface $entity) { // Only handle content entities and ignore config entities. - if ($entity instanceof ContentEntityInterface && \Drupal::service('business_rules.processor')->businessRulesExists('entity_insert', $entity)) { + if (\Drupal::service('business_rules.processor')->ruleExists('entity_insert', $entity)) { $reacts_on_definition = \Drupal::getContainer() ->get('plugin.manager.business_rules.reacts_on') ->getDefinition('entity_insert'); @@ -120,7 +119,7 @@ */ function business_rules_entity_delete(EntityInterface $entity) { // Only handle content entities and ignore config entities. - if ($entity instanceof ContentEntityInterface && \Drupal::service('business_rules.processor')->businessRulesExists('entity_delete', $entity)) { + if (\Drupal::service('business_rules.processor')->ruleExists('entity_delete', $entity)) { $reacts_on_definition = \Drupal::getContainer() ->get('plugin.manager.business_rules.reacts_on') ->getDefinition('entity_delete'); @@ -151,7 +150,7 @@ ) { $entity = $form_state->getFormObject()->getEntity(); - if ($entity instanceof ContentEntityInterface && \Drupal::service('business_rules.processor')->businessRulesExists('form_validation', $entity)) { + if (\Drupal::service('business_rules.processor')->ruleExists('form_validation', $entity)) { // Prepare the event for formValidation. $form_validation_reacts_on_definition = \Drupal::getContainer() @@ -294,7 +293,7 @@ */ function business_rules_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) { // Only handle content entities and ignore config entities. - if ($entity instanceof ContentEntityInterface && \Drupal::service('business_rules.processor')->businessRulesExists('entity_is_viewed', $entity)) { + if (\Drupal::service('business_rules.processor')->ruleExists('entity_is_viewed', $entity)) { $reacts_on_definition = \Drupal::getContainer() ->get('plugin.manager.business_rules.reacts_on') ->getDefinition('entity_is_viewed'); @@ -321,7 +320,7 @@ function business_rules_entity_load(array $entities, $entity_type_id) { foreach ($entities as $entity) { - if ($entity instanceof ContentEntityInterface && \Drupal::service('business_rules.processor')->businessRulesExists('entity_is_loaded', $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'); @@ -348,7 +347,7 @@ function business_rules_user_login($account) { $entity = $account; - if (\Drupal::service('business_rules.processor')->businessRulesExists('user_login', $entity)) { + if (\Drupal::service('business_rules.processor')->ruleExists('user_login', $entity)) { $reacts_on_definition = \Drupal::getContainer() ->get('plugin.manager.business_rules.reacts_on') ->getDefinition('user_login'); @@ -375,7 +374,7 @@ function business_rules_user_logout($account) { $entity = User::load($account->id()); - if (\Drupal::service('business_rules.processor')->businessRulesExists('user_logout', $entity)) { + if (\Drupal::service('business_rules.processor')->ruleExists('user_logout', $entity)) { $reacts_on_definition = \Drupal::getContainer() ->get('plugin.manager.business_rules.reacts_on') diff -u b/src/Util/BusinessRulesProcessor.php b/src/Util/BusinessRulesProcessor.php --- b/src/Util/BusinessRulesProcessor.php +++ b/src/Util/BusinessRulesProcessor.php @@ -11,6 +11,7 @@ use Drupal\business_rules\VariableObject; use Drupal\business_rules\VariablesSet; use Drupal\Core\Cache\Cache; +use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Link; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -715,7 +716,7 @@ } /** - * Check if Business Rule exist for the entity or not. + * Check if a Business Rule exists for the entity or not. * * @param string $reacts_on * The Event Name. @@ -723,12 +724,17 @@ * The Entity. * * @return bool - * Business Rule Exists for entity or not. + * TRUE if the business rule exists, FALSE otherwise. * * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ - public function businessRulesExists($reacts_on, EntityInterface $entity) { + public function ruleExists($reacts_on, EntityInterface $entity) { + + if (!($entity instanceof ContentEntityInterface)) { + return FALSE; + } + $business_rule_entity = $this->entityTypeManager ->getStorage('business_rule') ->loadByProperties(