public function BusinessRulesProcessor::getDebugRenderArray in Business Rules 2.x
Same name and namespace in other branches
- 8 src/Util/BusinessRulesProcessor.php \Drupal\business_rules\Util\BusinessRulesProcessor::getDebugRenderArray()
Generates the render array for business_rules debug.
Return value
array The render array.
1 call to BusinessRulesProcessor::getDebugRenderArray()
- BusinessRulesProcessor::saveDebugInfo in src/
Util/ BusinessRulesProcessor.php - Save the debug information.
File
- src/
Util/ BusinessRulesProcessor.php, line 400
Class
- BusinessRulesProcessor
- Class BusinessRulesProcessor.
Namespace
Drupal\business_rules\UtilCode
public function getDebugRenderArray() {
/** @var \Drupal\business_rules\Entity\BusinessRule $rule */
$triggered_rules = isset($this->debugArray['triggered_rules']) ? $this->debugArray['triggered_rules'] : [];
$evaluates_variables = isset($this->debugArray['variables']) ? $this->debugArray['variables'] : [];
$output = [];
if (!count($triggered_rules)) {
return $output;
}
foreach ($triggered_rules as $rule) {
$rule_link = Link::createFromRoute($rule
->id(), 'entity.business_rule.edit_form', [
'business_rule' => $rule
->id(),
]);
$output['triggered_rules'][$rule
->id()] = [
'#type' => 'details',
'#title' => $rule
->label(),
'#description' => $rule_link
->toString() . '<br>' . $rule
->getDescription(),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
];
if (isset($evaluates_variables[$rule
->id()]) && is_array($evaluates_variables[$rule
->id()])) {
$output['triggered_rules'][$rule
->id()]['variables'] = [
'#type' => 'details',
'#title' => $this
->t('Variables'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
];
/** @var \Drupal\business_rules\VariableObject $evaluates_variable */
foreach ($evaluates_variables[$rule
->id()] as $evaluates_variable) {
$variable = Variable::load($evaluates_variable
->getId());
if ($variable instanceof Variable) {
$variable_link = Link::createFromRoute($variable
->id(), 'entity.business_rules_variable.edit_form', [
'business_rules_variable' => $variable
->id(),
]);
$variable_value = empty($evaluates_variable
->getValue()) ? 'NULL' : $evaluates_variable
->getValue();
if (!is_string($variable_value) && !is_numeric($variable_value)) {
$serialized = serialize($variable_value);
if (is_object($variable_value)) {
// Transform the serialized object into serialized array.
$arr = explode(':', $serialized);
$arr[0] = 'a';
unset($arr[1]);
unset($arr[2]);
$serialized = implode(':', $arr);
}
$unserialized = unserialize($serialized);
$variable_value = Dbug::debug($unserialized, 'array');
}
$output['triggered_rules'][$rule
->id()]['variables'][$evaluates_variable
->getId()] = [
'#type' => 'details',
'#title' => $variable
->label(),
'#description' => $variable_link
->toString() . '<br>' . $variable
->getDescription() . '<br>' . $this
->t('Value:') . '<br>',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
];
$output['triggered_rules'][$rule
->id()]['variables'][$evaluates_variable
->getId()]['value'] = [
'#type' => 'markup',
'#markup' => $variable_value,
];
}
}
}
$output['triggered_rules'][$rule
->id()]['items'] = [
'#type' => 'details',
'#title' => $this
->t('Items'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
];
$items = $rule
->getItems();
$output['triggered_rules'][$rule
->id()]['items'][] = $this
->getDebugItems($items, $rule
->id());
}
return $output;
}