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))
));
}