Skip to content

Commit

Permalink
[Form] Renamed the internal FormView variables "types" and "full_bloc…
Browse files Browse the repository at this point in the history
…k_name"
  • Loading branch information
webmozart committed Jul 25, 2012
1 parent 6b17640 commit eeb66dd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
57 changes: 29 additions & 28 deletions src/Symfony/Component/Form/Extension/Core/Type/FormType.php
Expand Up @@ -71,11 +71,11 @@ public function buildView(FormView $view, FormInterface $form, array $options)
if ('' !== ($parentFullName = $view->parent->vars['full_name'])) {
$id = sprintf('%s_%s', $view->parent->vars['id'], $name);
$fullName = sprintf('%s[%s]', $parentFullName, $name);
$fullBlockName = sprintf('%s_%s', $view->parent->vars['full_block_name'], $blockName);
$uniqueBlockPrefix = sprintf('%s_%s', $view->parent->vars['unique_block_prefix'], $blockName);
} else {
$id = $name;
$fullName = $name;
$fullBlockName = '_' . $blockName;
$uniqueBlockPrefix = '_' . $blockName;
}

// Complex fields are read-only if they themselves or their parents are.
Expand All @@ -89,53 +89,54 @@ public function buildView(FormView $view, FormInterface $form, array $options)
} else {
$id = $name;
$fullName = $name;
$fullBlockName = '_' . $blockName;
$uniqueBlockPrefix = '_' . $blockName;

// Strip leading underscores and digits. These are allowed in
// form names, but not in HTML4 ID attributes.
// http://www.w3.org/TR/html401/struct/global.html#adef-id
$id = ltrim($id, '_0123456789');
}

$types = array();
$blockPrefixes = array();
for ($type = $form->getConfig()->getType(); null !== $type; $type = $type->getParent()) {
array_unshift($types, $type->getName());
array_unshift($blockPrefixes, $type->getName());
}
$blockPrefixes[] = $uniqueBlockPrefix;

if (!$translationDomain) {
$translationDomain = 'messages';
}

$view->vars = array_replace($view->vars, array(
'form' => $view,
'id' => $id,
'name' => $name,
'full_name' => $fullName,
'full_block_name' => $fullBlockName,
'read_only' => $readOnly,
'errors' => $form->getErrors(),
'valid' => $form->isBound() ? $form->isValid() : true,
'value' => $form->getViewData(),
'data' => $form->getNormData(),
'disabled' => $form->isDisabled(),
'required' => $form->isRequired(),
'max_length' => $options['max_length'],
'pattern' => $options['pattern'],
'size' => null,
'label' => $options['label'],
'multipart' => false,
'attr' => $options['attr'],
'label_attr' => $options['label_attr'],
'compound' => $form->getConfig()->getCompound(),
'types' => $types,
'translation_domain' => $translationDomain,
'form' => $view,
'id' => $id,
'name' => $name,
'full_name' => $fullName,
'read_only' => $readOnly,
'errors' => $form->getErrors(),
'valid' => $form->isBound() ? $form->isValid() : true,
'value' => $form->getViewData(),
'data' => $form->getNormData(),
'disabled' => $form->isDisabled(),
'required' => $form->isRequired(),
'max_length' => $options['max_length'],
'pattern' => $options['pattern'],
'size' => null,
'label' => $options['label'],
'multipart' => false,
'attr' => $options['attr'],
'label_attr' => $options['label_attr'],
'compound' => $form->getConfig()->getCompound(),
'block_prefixes' => $blockPrefixes,
'unique_block_prefix' => $uniqueBlockPrefix,
'translation_domain' => $translationDomain,
// Using the block name here speeds up performance in collection
// forms, where each entry has the same full block name.
// Including the type is important too, because if rows of a
// collection form have different types (dynamically), they should
// be rendered differently.
// https://github.com/symfony/symfony/issues/5038
'cache_key' => $fullBlockName . '_' . $form->getConfig()->getType()->getName(),
'cache_key' => $uniqueBlockPrefix . '_' . $form->getConfig()->getType()->getName(),
));
}

Expand Down
7 changes: 3 additions & 4 deletions src/Symfony/Component/Form/FormRenderer.php
Expand Up @@ -22,7 +22,7 @@
*/
class FormRenderer implements FormRendererInterface
{
const CACHE_KEY_VAR = 'full_block_name';
const CACHE_KEY_VAR = 'unique_block_prefix';

/**
* @var FormRendererEngineInterface
Expand Down Expand Up @@ -173,10 +173,9 @@ public function searchAndRenderBlock(FormView $view, $blockNameSuffix, array $va
// Calculate the hierarchy of template blocks and start on
// the bottom level of the hierarchy (= "_<id>_<section>" block)
$blockNameHierarchy = array();
foreach ($view->vars['types'] as $type) {
$blockNameHierarchy[] = $type . '_' . $blockNameSuffix;
foreach ($view->vars['block_prefixes'] as $blockNamePrefix) {
$blockNameHierarchy[] = $blockNamePrefix . '_' . $blockNameSuffix;
}
$blockNameHierarchy[] = $view->vars['full_block_name'] . '_' . $blockNameSuffix;
$hierarchyLevel = count($blockNameHierarchy) - 1;

$hierarchyInit = true;
Expand Down

0 comments on commit eeb66dd

Please sign in to comment.