Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Form] Renamed view variable "name" to "full_name"
The variable "name" now contains the local, short name (equivalent to $form->getName()).
  • Loading branch information
webmozart committed May 18, 2011
1 parent b39a21f commit f467317
Show file tree
Hide file tree
Showing 21 changed files with 31 additions and 24 deletions.
3 changes: 3 additions & 0 deletions UPDATE.md
Expand Up @@ -167,6 +167,9 @@ beta1 to beta2
* Form: Renamed option value "text" of "widget" option of the "date" type was
renamed to "single-text". "text" indicates to use separate text boxes now
(like for the "time" type).

* Form: Renamed view variable "name" to "full_name". The variable "name" now
contains the local, short name (equivalent to $form->getName()).

PR12 to beta1
-------------
Expand Down
@@ -1,6 +1,6 @@
<input type="checkbox"
<?php echo $view['form']->attributes() ?>
name="<?php echo $view->escape($name) ?>"
name="<?php echo $view->escape($full_name) ?>"
<?php if ($value): ?>value="<?php echo $view->escape($value) ?>"<?php endif ?>
<?php if ($read_only): ?>disabled="disabled"<?php endif ?>
<?php if ($required): ?>required="required"<?php endif ?>
Expand Down
Expand Up @@ -8,7 +8,7 @@
<?php else: ?>
<select
<?php echo $view['form']->attributes() ?>
name="<?php echo $view->escape($name) ?>"
name="<?php echo $view->escape($full_name) ?>"
<?php if ($read_only): ?> disabled="disabled"<?php endif ?>
<?php if ($multiple): ?> multiple="multiple"<?php endif ?>
>
Expand Down
@@ -1,7 +1,7 @@
<?php if ($widget == 'single-text'): ?>
<input type="text"
<?php echo $view['form']->attributes() ?>
name="<?php echo $view->escape($name) ?>"
name="<?php echo $view->escape($full_name) ?>"
value="<?php echo $view->escape($value) ?>"
<?php if ($read_only): ?>disabled="disabled"<?php endif ?>
<?php if ($required): ?>required="required"<?php endif ?>
Expand Down
@@ -1,6 +1,6 @@
<input type="email"
<?php echo $view['form']->attributes() ?>
name="<?php echo $view->escape($name) ?>"
name="<?php echo $view->escape($full_name) ?>"
value="<?php echo $view->escape($value) ?>"
<?php if ($max_length): ?>maxlength="<?php echo $view->escape($max_length) ?>"<?php endif ?>
<?php if ($read_only): ?>disabled="disabled"<?php endif ?>
Expand Down
@@ -1,6 +1,6 @@
<input
<?php echo $view['form']->attributes() ?>
name="<?php echo $view->escape($name) ?>"
name="<?php echo $view->escape($full_name) ?>"
value="<?php echo $view->escape($value) ?>"
<?php if ($read_only): ?>disabled="disabled"<?php endif ?>
<?php if ($required): ?>required="required"<?php endif ?>
Expand Down
@@ -1,6 +1,6 @@
<input type="hidden"
<?php echo $view['form']->attributes() ?>
name="<?php echo $view->escape($name) ?>"
name="<?php echo $view->escape($full_name) ?>"
value="<?php echo $view->escape($value) ?>"
<?php if ($read_only): ?>disabled="disabled"<?php endif ?>
/>
@@ -1,6 +1,6 @@
<input type="number"
<?php echo $view['form']->attributes() ?>
name="<?php echo $view->escape($name) ?>"
name="<?php echo $view->escape($full_name) ?>"
value="<?php echo $view->escape($value) ?>"
<?php if ($read_only): ?>disabled="disabled"<?php endif ?>
<?php if ($required): ?>required="required"<?php endif ?>
Expand Down
@@ -1,6 +1,6 @@
<input type="text"
<?php echo $view['form']->attributes() ?>
name="<?php echo $view->escape($name) ?>"
name="<?php echo $view->escape($full_name) ?>"
value="<?php echo $view->escape($value) ?>"
<?php if ($read_only): ?>disabled="disabled"<?php endif ?>
<?php if ($required): ?>required="required"<?php endif ?>
Expand Down
@@ -1,6 +1,6 @@
<input type="password"
<?php echo $view['form']->attributes() ?>
name="<?php echo $view->escape($name) ?>"
name="<?php echo $view->escape($full_name) ?>"
value="<?php echo $view->escape($value) ?>"
<?php if ($read_only): ?>disabled="disabled"<?php endif ?>
<?php if ($required): ?>required="required"<?php endif ?>
Expand Down
@@ -1,6 +1,6 @@
<input type="radio"
<?php echo $view['form']->attributes() ?>
name="<?php echo $view->escape($name) ?>"
name="<?php echo $view->escape($full_name) ?>"
value="<?php echo $view->escape($value) ?>"
<?php if ($read_only): ?>disabled="disabled"<?php endif ?>
<?php if ($required): ?>required="required"<?php endif ?>
Expand Down
@@ -1,6 +1,6 @@
<input type="text"
<?php echo $view['form']->attributes() ?>
name="<?php echo $view->escape($name) ?>"
name="<?php echo $view->escape($full_name) ?>"
value="<?php echo $view->escape($value) ?>"
<?php if ($read_only): ?>disabled="disabled"<?php endif ?>
<?php if ($required): ?>required="required"<?php endif ?>
Expand Down
@@ -1,6 +1,6 @@
<textarea
<?php echo $view['form']->attributes() ?>
name="<?php echo $view->escape($name) ?>"
name="<?php echo $view->escape($full_name) ?>"
<?php if ($read_only): ?>disabled="disabled"<?php endif ?>
<?php if ($required): ?>required="required"<?php endif ?>
><?php echo $view->escape($value) ?></textarea>
@@ -1,6 +1,6 @@
<input type="url"
<?php echo $view['form']->attributes() ?>
name="<?php echo $view->escape($name) ?>"
name="<?php echo $view->escape($full_name) ?>"
value="<?php echo $view->escape($value) ?>"
<?php if ($read_only): ?>disabled="disabled"<?php endif ?>
<?php if ($required): ?>required="required"<?php endif ?>
Expand Down
Expand Up @@ -43,7 +43,7 @@

{% block attributes %}
{% spaceless %}
id="{{ id }}" name="{{ name }}"{% if read_only %} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}{% if max_length %} maxlength="{{ max_length }}"{% endif %}
id="{{ id }}" name="{{ full_name }}"{% if read_only %} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}{% if max_length %} maxlength="{{ max_length }}"{% endif %}
{% for attrname,attrvalue in attr %}{{attrname}}="{{attrvalue}}" {% endfor %}
{% endspaceless %}
{% endblock attributes %}
Expand Down
Expand Up @@ -106,7 +106,7 @@ public function buildView(FormView $view, FormInterface $form)
// Add "[]" to the name in case a select tag with multiple options is
// displayed. Otherwise only one of the selected options is sent in the
// POST request.
$view->set('name', $view->get('name').'[]');
$view->set('full_name', $view->get('full_name').'[]');
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/FieldType.php
Expand Up @@ -58,7 +58,7 @@ public function buildView(FormView $view, FormInterface $form)
{
if ($view->hasParent()) {
$parentId = $view->getParent()->get('id');
$parentName = $view->getParent()->get('name');
$parentName = $view->getParent()->get('full_name');
$id = sprintf('%s_%s', $parentId, $form->getName());
$name = sprintf('%s[%s]', $parentName, $form->getName());
} else {
Expand All @@ -69,7 +69,8 @@ public function buildView(FormView $view, FormInterface $form)
$view
->set('form', $view)
->set('id', $id)
->set('name', $name)
->set('name', $form->getName())
->set('full_name', $name)
->set('errors', $form->getErrors())
->set('value', $form->getClientData())
->set('read_only', $form->isReadOnly())
Expand Down
Expand Up @@ -35,7 +35,7 @@ public function buildView(FormView $view, FormInterface $form)
;

if ($view->hasParent()) {
$view->set('name', $view->getParent()->get('name'));
$view->set('full_name', $view->getParent()->get('full_name'));
}
}

Expand Down
Expand Up @@ -312,7 +312,7 @@ public function testPassPreferredChoicesToView()
$this->assertSame(array('b' => 'B', 'd' => 'D'), $view->get('preferred_choices'));
}

public function testAdjustNameForMultipleNonExpanded()
public function testAdjustFullNameForMultipleNonExpanded()
{
$form = $this->factory->createNamed('choice', 'name', null, array(
'multiple' => true,
Expand All @@ -321,6 +321,6 @@ public function testAdjustNameForMultipleNonExpanded()
));
$view = $form->createView();

$this->assertSame('name[]', $view->get('name'));
$this->assertSame('name[]', $view->get('full_name'));
}
}
Expand Up @@ -117,6 +117,7 @@ public function testPassIdAndNameToView()

$this->assertEquals('name', $view->get('id'));
$this->assertEquals('name', $view->get('name'));
$this->assertEquals('name', $view->get('full_name'));
}

public function testPassIdAndNameToViewWithParent()
Expand All @@ -126,7 +127,8 @@ public function testPassIdAndNameToViewWithParent()
$view = $parent->createView();

$this->assertEquals('parent_child', $view['child']->get('id'));
$this->assertEquals('parent[child]', $view['child']->get('name'));
$this->assertEquals('child', $view['child']->get('name'));
$this->assertEquals('parent[child]', $view['child']->get('full_name'));
}

public function testPassIdAndNameToViewWithGrandParent()
Expand All @@ -137,7 +139,8 @@ public function testPassIdAndNameToViewWithGrandParent()
$view = $parent->createView();

$this->assertEquals('parent_child_grand_child', $view['child']['grand_child']->get('id'));
$this->assertEquals('parent[child][grand_child]', $view['child']['grand_child']->get('name'));
$this->assertEquals('grand_child', $view['child']['grand_child']->get('name'));
$this->assertEquals('parent[child][grand_child]', $view['child']['grand_child']->get('full_name'));
}

public function testPassMaxLengthToView()
Expand Down
Expand Up @@ -21,13 +21,13 @@ public function testPassValueToView()
$this->assertEquals('foobar', $view->get('value'));
}

public function testPassParentNameToView()
public function testPassParentFullNameToView()
{
$parent = $this->factory->createNamed('field', 'parent');
$parent->add($this->factory->createNamed('radio', 'child'));
$view = $parent->createView();

$this->assertEquals('parent', $view['child']->get('name'));
$this->assertEquals('parent', $view['child']->get('full_name'));
}

public function testCheckedIfDataTrue()
Expand Down

0 comments on commit f467317

Please sign in to comment.