Skip to content

[Form] Merged FormHelper and FormExtension and implemented a better caching strategy #4918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 18, 2012
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Form] Fixed passing of variables in the FormRenderer
  • Loading branch information
webmozart committed Jul 16, 2012
commit d11f8b5e9e49b10bf1c688426fbd9b32692877cc
32 changes: 29 additions & 3 deletions src/Symfony/Component/Form/FormRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,19 @@ public function renderBlock($block, array $variables = array())
throw new FormException(sprintf('No block "%s" found while rendering the form.', $block));
}

$variables = array_replace_recursive($scopeVariables, $variables);
// Merge the passed with the existing attributes
if (isset($variables['attr']) && isset($scopeVariables['attr'])) {
$variables['attr'] = array_replace($scopeVariables['attr'], $variables['attr']);
}

// Merge the passed with the exist *label* attributes
if (isset($variables['label_attr']) && isset($scopeVariables['label_attr'])) {
$variables['label_attr'] = array_replace($scopeVariables['label_attr'], $variables['label_attr']);
}

// Do not use array_replace_recursive(), otherwise array variables
// cannot be overwritten
$variables = array_replace($scopeVariables, $variables);

return $this->engine->renderBlock($view, $resource, $block, $variables);
}
Expand Down Expand Up @@ -253,7 +265,7 @@ protected function renderSection(FormViewInterface $view, $section, array $varia

// The default variable scope contains all view variables, merged with
// the variables passed explicitely to the helper
$variables = array_replace_recursive($view->getVars(), $variables);
$scopeVariables = $view->getVars();
} else {
// RECURSIVE CALL
// If a block recursively calls renderSection() again, resume rendering
Expand All @@ -262,7 +274,7 @@ protected function renderSection(FormViewInterface $view, $section, array $varia
$hierarchyLevel = $this->hierarchyLevelMap[$mapKey] - 1;

// Reuse the current scope and merge it with the explicitely passed variables
$variables = array_replace_recursive($this->variableMap[$mapKey], $variables);
$scopeVariables = $this->variableMap[$mapKey];
}

// Load the resource where this block can be found
Expand All @@ -285,6 +297,20 @@ protected function renderSection(FormViewInterface $view, $section, array $varia
));
}

// Merge the passed with the existing attributes
if (isset($variables['attr']) && isset($scopeVariables['attr'])) {
$variables['attr'] = array_replace($scopeVariables['attr'], $variables['attr']);
}

// Merge the passed with the exist *label* attributes
if (isset($variables['label_attr']) && isset($scopeVariables['label_attr'])) {
$variables['label_attr'] = array_replace($scopeVariables['label_attr'], $variables['label_attr']);
}

// Do not use array_replace_recursive(), otherwise array variables
// cannot be overwritten
$variables = array_replace($scopeVariables, $variables);

// In order to make recursive calls possible, we need to store the block hierarchy,
// the current level of the hierarchy and the variables so that this method can
// resume rendering one level higher of the hierarchy when it is called recursively.
Expand Down