Skip to content

Commit

Permalink
[Order] Make Form::types and FormView::types use the same order (Pare…
Browse files Browse the repository at this point in the history
…nt > Child)
  • Loading branch information
vicb committed Jun 14, 2011
1 parent e56dad6 commit b709551
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 28 deletions.
10 changes: 5 additions & 5 deletions src/Symfony/Bridge/Twig/Extension/FormExtension.php
Expand Up @@ -226,20 +226,20 @@ protected function render(FormView $view, $section, array $variables = array())

$blocks = $this->getBlocks($view);
$types = $view->get('types');
array_unshift($types, '_'.$view->get('proto_id', $view->get('id')));
$types[] = '_'.$view->get('proto_id', $view->get('id'));

foreach ($types as &$block) {
$block = $block.'_'.$section;
for ($i = count($types) - 1; $i >= 0; $i--) {
$types[$i] .= '_'.$section;

if (isset($blocks[$block])) {
if (isset($blocks[$types[$i]])) {

$this->varStack[$view] = array_replace(
$view->all(),
isset($this->varStack[$view]) ? $this->varStack[$view] : array(),
$variables
);

$html = $this->template->renderBlock($block, $this->varStack[$view], $blocks);
$html = $this->template->renderBlock($types[$i], $this->varStack[$view], $blocks);

if ($mainTemplate) {
$view->setRendered();
Expand Down
28 changes: 12 additions & 16 deletions src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php
Expand Up @@ -202,29 +202,25 @@ protected function renderSection(FormView $view, $section, array $variables = ar
}

$template = null;
$blocks = $view->get('types');
array_unshift($blocks, '_'.$view->get('proto_id', $view->get('id')));
$types = $view->get('types');
$types[] = '_'.$view->get('proto_id', $view->get('id'));

foreach ($blocks as &$block) {
$block = $block.'_'.$section;
$template = $this->lookupTemplate($block);
for ($i = count($types) - 1; $i >= 0; $i--) {
$types[$i] .= '_'.$section;
$template = $this->lookupTemplate($types[$i]);

if ($template) {
break;
}
}

if (!$template) {
throw new FormException(sprintf('Unable to render form as none of the following blocks exist: "%s".', implode('", "', $blocks)));
}
$html = $this->render($view, $template, $variables);

$html = $this->render($view, $template, $variables);
if ($mainTemplate) {
$view->setRendered();
}

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

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

public function render(FormView $view, $template, array $variables = array())
Expand Down
7 changes: 1 addition & 6 deletions src/Symfony/Component/Form/Extension/Core/Type/FieldType.php
Expand Up @@ -75,11 +75,6 @@ public function buildView(FormView $view, FormInterface $form)
$fullName = $name;
}

$types = array();
foreach (array_reverse((array) $form->getTypes()) as $type) {
$types[] = $type->getName();
}

$view
->set('form', $view)
->set('id', $id)
Expand All @@ -95,7 +90,7 @@ public function buildView(FormView $view, FormInterface $form)
->set('label', $form->getAttribute('label'))
->set('multipart', false)
->set('attr', array())
->set('types', $types)
->set('types', array_map(function ($type) { return $type->getName(); }, $form->getTypes()))
;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/Form.php
Expand Up @@ -921,7 +921,7 @@ public function createView(FormView $parent = null)
if (null !== $prototype = $view->get('prototype')) {
$protoView = $prototype->getForm()->createView($view);
$protoTypes = $protoView->get('types');
array_unshift($protoTypes, 'prototype');
$protoTypes[] = 'prototype';
$childViews[$prototype->getName()] = $protoView
->set('types', $protoTypes)
->set('proto_id', $view->get('id').'_prototype');
Expand Down

0 comments on commit b709551

Please sign in to comment.