/** * {@inheritdoc} */ public function buildView(BlockView $view, BlockInterface $block, array $options) { // merge the passed variables with the existing ones if (!empty($options['vars'])) { $view->vars = array_replace($view->vars, $options['vars']); } // add the view to itself vars to allow get it using 'block' variable in a rendered, for example TWIG $view->vars['block'] = $view; // 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['label']; if (isset($options['label_attr'])) { $view->vars['label_attr'] = $options['label_attr']; } } // add the translation domain $view->vars['translation_domain'] = $this->getTranslationDomain($view, $options); // add core variables to the block view, like id, block type and variables required for rendering engine $id = $block->getId(); $name = $block->getTypeName(); // the block prefix must contain only letters, numbers and underscores (_) // due to limitations of block names in TWIG $uniqueBlockPrefix = '_' . preg_replace('/[^a-z0-9_]+/i', '_', $id); $blockPrefixes = $block->getTypeHelper()->getTypeNames($name); $blockPrefixes[] = $uniqueBlockPrefix; $view->vars['id'] = $id; $view->vars['block_type'] = $name; $view->vars['unique_block_prefix'] = $uniqueBlockPrefix; $view->vars['block_prefixes'] = $blockPrefixes; $view->vars['cache_key'] = sprintf('_%s_%s', $id, $name); }
/** * {@inheritdoc} */ public function finishView(BlockView $view, BlockInterface $block, array $options) { $context = $block->getContext(); $evaluate = $context->getOr('expressions_evaluate'); $encoding = $context->getOr('expressions_encoding'); if ($evaluate || $encoding !== null) { $this->processExpressions($view->vars, $context, $block->getData(), $evaluate, $encoding); } }
/** * {@inheritdoc} */ public function finishView(BlockView $view, BlockInterface $block, array $options) { $context = $block->getContext(); $data = $block->getData(); if (true !== $context->getOr('expressions_evaluate_deferred')) { return; } $evaluate = $context->getOr('expressions_evaluate'); $encoding = $context->getOr('expressions_encoding'); $this->processor->processExpressions($view->vars, $context, $data, $evaluate, $encoding); }
/** * {@inheritdoc} */ public function finishView(BlockView $view, BlockInterface $block, array $options) { $context = $block->getContext(); if ($context->getOr('expressions_evaluate')) { parent::finishView($view, $block, $options); } else { $encoding = $context->getOr('expressions_encoding'); if ($encoding !== null) { $this->normalizeClassAttributeWithEncoding($view, 'attr', $encoding); $this->normalizeClassAttributeWithEncoding($view, 'label_attr', $encoding); } } }
/** * {@inheritdoc} */ public function finishView(BlockView $view, BlockInterface $block, array $options) { $formAccessor = $this->getFormAccessor($block->getContext(), $options); // prevent form fields rendering by form_rest() method, // if the corresponding layout block has been removed foreach ($formAccessor->getProcessedFields() as $formFieldPath => $blockId) { if (isset($view[$blockId])) { $this->checkExistingFieldView($view, $view[$blockId], $formFieldPath); continue; } if (isset($view->blocks[$blockId])) { $this->checkExistingFieldView($view, $view->blocks[$blockId], $formFieldPath); continue; } $this->getFormFieldView($view, $formFieldPath)->setRendered(); } }
/** * {@inheritdoc} */ public function finishView(BlockView $view, BlockInterface $block, array $options) { $formAccessor = $this->getFormAccessor($block->getContext(), $options); $view->vars['form'] = $formAccessor->getView(); // final check of the view vars and their modification (if required) // we have to do this in the finishView because only here we can be sure that // expressions have been evaluated (if $context.expressions_evaluate is true) if (empty($view->vars['action_path'])) { unset($view->vars['action_path']); } if (empty($view->vars['action_route_name'])) { unset($view->vars['action_route_name'], $view->vars['action_route_parameters']); } if (empty($view->vars['method'])) { unset($view->vars['method']); } if (empty($view->vars['enctype'])) { unset($view->vars['enctype']); } }
/** * {@inheritdoc} * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function buildView(BlockView $view, BlockInterface $block, array $options) { $formAccessor = $this->getFormAccessor($block->getContext(), $options); $view->vars['form'] = $formAccessor->getView(); // form action if (isset($options['form_action'])) { $path = $options['form_action']; if ($path) { $view->vars['action_path'] = $path; } } elseif (isset($options['form_route_name'])) { $routeName = $options['form_route_name']; if ($routeName) { $view->vars['action_route_name'] = $routeName; $view->vars['action_route_parameters'] = isset($options['form_route_parameters']) ? $options['form_route_parameters'] : []; } } else { $action = $formAccessor->getAction(); $path = $action->getPath(); if ($path) { $view->vars['action_path'] = $path; } else { $routeName = $action->getRouteName(); if ($routeName) { $view->vars['action_route_name'] = $routeName; $view->vars['action_route_parameters'] = $action->getRouteParameters(); } } } // form method $method = isset($options['form_method']) ? strtoupper($options['form_method']) : $formAccessor->getMethod(); if ($method) { $view->vars['method'] = $method; } // form enctype $enctype = isset($options['form_enctype']) ? $options['form_enctype'] : $formAccessor->getEnctype(); if ($enctype) { $view->vars['enctype'] = $enctype; } }
/** * {@inheritdoc} */ public function buildView(BlockView $view, BlockInterface $block, array $options) { $formAccessor = $this->getFormAccessor($block->getContext(), $options); $view->vars['form'] = $formAccessor->getView(); }