You are here

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

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

Return a details box which rules in where this item is being used.

Parameters

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

Return value

array The render array.

File

src/Util/BusinessRulesUtil.php, line 978

Class

BusinessRulesUtil
Class BusinessRulesUtil.

Namespace

Drupal\business_rules\Util

Code

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

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