You are here

public function BusinessRulesUtil::getActionsUsingItem in Business Rules 2.x

Same name and namespace in other branches
  1. 8 src/Util/BusinessRulesUtil.php \Drupal\business_rules\Util\BusinessRulesUtil::getActionsUsingItem()

Get all actions using the item.

Parameters

\Drupal\business_rules\ItemInterface $item: The item to look for actions using it.

Return value

array Actions using the item.

2 calls to BusinessRulesUtil::getActionsUsingItem()
BusinessRulesUtil::getUsedByActionsDetailsBox in src/Util/BusinessRulesUtil.php
Return a details box which actions using this item.
BusinessRulesUtil::removeItemReferences in src/Util/BusinessRulesUtil.php
Remove the item references after it's deletion.

File

src/Util/BusinessRulesUtil.php, line 915

Class

BusinessRulesUtil
Class BusinessRulesUtil.

Namespace

Drupal\business_rules\Util

Code

public function getActionsUsingItem(ItemInterface $item) {
  $actions = Action::loadMultiple();
  $used_by = [];

  /** @var \Drupal\business_rules\Entity\Action $action */
  if ($item instanceof Variable) {
    foreach ($actions as $action) {

      /** @var \Drupal\business_rules\VariablesSet $variables */
      $variables = $action
        ->getVariables();
      if ($variables
        ->count()) {

        /** @var \Drupal\business_rules\VariableObject $variable */
        foreach ($variables
          ->getVariables() as $variable) {
          if ($variable
            ->getId() == $item
            ->id()) {
            $used_by[$variable
              ->getId()] = $action;
          }
        }
      }
    }
  }
  else {
    foreach ($actions as $key => $action) {
      if ($action
        ->getSettings('items') && in_array($item
        ->id(), array_keys($action
        ->getSettings('items')))) {
        $used_by[$key] = $action;
      }
    }
  }
  return $used_by;
}