You are here

public function BusinessRule::filterContextAvailableItems in Business Rules 8

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

Return a list of Conditions|Actions compatible with the Rule.

Parameters

array $items: Array of Conditions|Actions.

Return value

array The available items considering the rule context.

Overrides BusinessRuleInterface::filterContextAvailableItems

File

src/Entity/BusinessRule.php, line 442

Class

BusinessRule
Defines the Rule entity.

Namespace

Drupal\business_rules\Entity

Code

public function filterContextAvailableItems(array $items) {

  /** @var \Drupal\business_rules\ItemInterface $value */
  $entity_type = $this
    ->getTargetEntityType();
  $bundle = $this
    ->getTargetBundle();
  $available_items = [];
  foreach ($items as $key => $value) {

    // Evaluate Target Entity Type.
    if (($value
      ->getTargetEntityType() == $entity_type || empty($value
      ->getTargetEntityType())) && ($value
      ->getTargetBundle() == $bundle || empty($value
      ->getTargetBundle())) && (in_array($this
      ->getReactsOn(), $value
      ->getReactOnEvents()) || count($value
      ->getReactOnEvents()) === 0) || !$value
      ->isContextDependent()) {
      $available_items[$key] = $value;
    }
  }
  return $available_items;
}