You are here

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

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

Return a details box which conditions using this item.

Parameters

\Drupal\business_rules\ItemInterface $item: The item to get the conditions using it.

Return value

array The render array.

File

src/Util/BusinessRulesUtil.php, line 1024

Class

BusinessRulesUtil
Class BusinessRulesUtil.

Namespace

Drupal\business_rules\Util

Code

public function getUsedByConditionsDetailsBox(ItemInterface $item) {
  $used_by = $this
    ->getConditionsUsingItem($item);
  $details = [];
  if (count($used_by)) {

    /** @var \Drupal\business_rules\Entity\Condition $condition */
    $condition = $used_by[array_keys($used_by)[0]];
    $storage = $this->entityTypeManager
      ->getStorage('business_rules_condition');
    $list = new ConditionListBuilder($condition
      ->getEntityType(), $storage);
    $details = [
      '#type' => 'details',
      '#title' => $this
        ->t('Conditions using this item'),
      '#collapsed' => TRUE,
      '#collapsable' => TRUE,
    ];
    $header = $list
      ->buildHeader();
    $rows = [];
    foreach ($used_by as $condition) {
      $rows[] = $list
        ->buildRow($condition);
    }
    $details['used_by'] = [
      '#type' => 'table',
      '#header' => $header,
      '#rows' => $rows,
    ];
  }
  return $details;
}