You are here

public function Condition::filterContextAvailableItems in Business Rules 2.x

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

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

Parameters

array $items: Array of items.

Return value

array The available items considering the condition context.

Overrides ConditionInterface::filterContextAvailableItems

File

src/Entity/Condition.php, line 174

Class

Condition
Defines the Condition 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())) || !$value
      ->isContextDependent()) && $this
      ->id() != $value
      ->id()) {
      $available_items[$key] = $value;
    }
  }
  return $available_items;
}