You are here

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

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

Get a variables options array.

Parameters

array $variable_types: The variable type. Leave empty if you need all variables..

array $entity_type: Variable entity type. Empty for all.

array $bundle: Variable bundle. Empty for all.

Return value

array Options array.

File

src/Util/BusinessRulesUtil.php, line 695

Class

BusinessRulesUtil
Class BusinessRulesUtil.

Namespace

Drupal\business_rules\Util

Code

public function getVariablesOptions(array $variable_types = [], array $entity_type = [], array $bundle = []) {
  $options = [];
  $variables = Variable::loadMultiple();

  /** @var \Drupal\business_rules\Entity\Variable $variable */
  foreach ($variables as $variable) {
    if ((!count($variable_types) || in_array($variable
      ->getType(), $variable_types)) && (!count($entity_type) || in_array($variable
      ->getTargetEntityType(), $entity_type)) && (!count($bundle) || in_array($variable
      ->getTargetBundle(), $bundle))) {
      $options[$variable
        ->id()] = $variable
        ->label() . ' [' . $variable
        ->id() . ']';
    }
  }
  asort($options);
  return $options;
}