Symfony\Bundle\FrameworkBundle\Templating\Helper\FormHelper::renderSection PHP Method

renderSection() protected method

1. This function first looks for a block named "__
", 2. if such a block is not found the function will look for a block named "_
", 3. the type name is recursively replaced by the parent type name until a corresponding block is found
protected renderSection ( Symfony\Component\Form\FormView $view, string $section, array $variables = [] ) : string
$view Symfony\Component\Form\FormView The form view
$section string The section to render (i.e. 'row', 'widget', 'label', ...)
$variables array Additional variables
return string The html markup
    protected function renderSection(FormView $view, $section, array $variables = array())
    {
        $mainTemplate = in_array($section, array('row', 'widget'));
        if ($mainTemplate && $view->isRendered()) {

                return '';
        }

        $template = null;

        $custom = '_'.$view->get('proto_id', $view->get('id'));
        $rendering = $custom.$section;

        if (isset($this->varStack[$rendering])) {
            $typeIndex = $this->varStack[$rendering]['typeIndex'] - 1;
            $types = $this->varStack[$rendering]['types'];
            $variables = array_replace_recursive($this->varStack[$rendering]['variables'], $variables);
        } else {
            $types = $view->get('types');
            $types[] = $custom;
            $typeIndex = count($types) - 1;
            $variables = array_replace_recursive($view->all(), $variables);
            $this->varStack[$rendering]['types'] = $types;
        }

        $this->varStack[$rendering]['variables'] = $variables;

        do {
            $types[$typeIndex] .= '_'.$section;
            $template = $this->lookupTemplate($view, $types[$typeIndex]);

            if ($template) {

                $this->varStack[$rendering]['typeIndex'] = $typeIndex;

                $this->context[] = array(
                    'variables' => $variables,
                    'view'      => $view,
                );

                $html = $this->engine->render($template, $variables);

                array_pop($this->context);
                unset($this->varStack[$rendering]);

                if ($mainTemplate) {
                    $view->setRendered();
                }

                return $html;
            }
        }  while (--$typeIndex >= 0);

        throw new FormException(sprintf(
            'Unable to render the form as none of the following blocks exist: "%s".',
            implode('", "', array_reverse($types))
        ));
    }