Programming Language PHP
Namespace Oro\Component\Layout\Util
Class BlockUtils
Method/Function populateComputedViewVars
Total Examples 2
2 code examples of PHP Oro\Component\Layout\Util\BlockUtils::populateComputedViewVars extracted from open source projects
/**
* @inheritdoc
*/
public function buildView(BlockView $view, BlockInterface $block, Options $options)
{
BlockUtils::setViewVarsFromOptions(
$view,
$options,
['visible', 'translation_domain', 'additional_block_prefixes', 'class_prefix']
);
// merge the passed variables with the existing ones
if (!empty($options['vars'])) {
foreach ($options['vars'] as $name => $value) {
$view->vars[$name] = $value;
}
}
// replace attributes if specified ('attr' variable always exists in a view because it is added by FormView)
if (isset($options['attr'])) {
$view->vars['attr'] = $options['attr'];
}
// add label text and attributes if specified
if (isset($options['label'])) {
$view->vars['label'] = $options->get('label', false);
$view->vars['label_attr'] = [];
if (isset($options['label_attr'])) {
$view->vars['label_attr'] = $options->get('label_attr', false);
}
}
// add core variables to the block view, like id, block type and variables required for rendering engine
$view->vars['id'] = $block->getId();
$view->vars['block_type'] = $block->getTypeName();
BlockUtils::populateComputedViewVars($view->vars, $block->getContext()->getHash());
}
protected function populateComputed(array &$vars, string $contextHash): void
{
if (!\array_key_exists(self::CLASS_PREFIX, $vars)) {
$vars[self::CLASS_PREFIX] = null;
}
BlockUtils::populateComputedViewVars($vars, $contextHash);
}