You are here

public function BusinessRule::checkItemContext in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Entity/BusinessRule.php \Drupal\business_rules\Entity\BusinessRule::checkItemContext()

Check if the item is on the same context as the Business Rule.

Parameters

\Drupal\business_rules\BusinessRulesItemObject $itemObject: The business rule object.

Return value

bool If the item is on the same context as the business rule.

Overrides BusinessRuleInterface::checkItemContext

1 call to BusinessRule::checkItemContext()
BusinessRule::save in src/Entity/BusinessRule.php
Saves an entity permanently.

File

src/Entity/BusinessRule.php, line 192

Class

BusinessRule
Defines the Rule entity.

Namespace

Drupal\business_rules\Entity

Code

public function checkItemContext(BusinessRulesItemObject $itemObject) {
  if ($itemObject
    ->getType() == 'condition') {
    $item = Condition::load($itemObject
      ->getId());
  }
  elseif ($itemObject
    ->getType() == 'action') {
    $item = Action::load($itemObject
      ->getId());
  }
  if (empty($item)) {
    return FALSE;
  }
  $entity_type = $this
    ->getTargetEntityType();
  $bundle = $this
    ->getTargetBundle();

  // Evaluate Target Entity Type.
  if (($item
    ->getTargetEntityType() == $entity_type || empty($item
    ->getTargetEntityType())) && ($item
    ->getTargetBundle() == $bundle || empty($item
    ->getTargetBundle())) && (in_array($this
    ->getReactsOn(), $item
    ->getReactOnEvents()) || count($item
    ->getReactOnEvents()) === 0) || !$item
    ->isContextDependent()) {
    return TRUE;
  }
  else {
    return FALSE;
  }
}