You are here

public function Condition::filterContextAvailableItems in Business Rules 8

Same name and namespace in other branches
  1. 2.x 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 150

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;
}