Updated vendors

master
Polonkai Gergely 11 years ago
parent b82b4ffd34
commit b9e6708ffd

@ -3,7 +3,7 @@
"name": "jms/metadata",
"version": "1.1.1",
"version_normalized": "1.1.1.0",
"time": "2011-12-29 14:32:49",
"time": "2011-12-29 12:32:49",
"source": {
"type": "git",
"url": "https://github.com/schmittjoh/metadata",
@ -47,7 +47,7 @@
"name": "jms/cg",
"version": "1.0.0",
"version_normalized": "1.0.0.0",
"time": "2011-12-29 13:40:52",
"time": "2011-12-29 11:40:52",
"source": {
"type": "git",
"url": "git://github.com/schmittjoh/cg-library.git",
@ -89,7 +89,7 @@
"version": "1.0.0",
"version_normalized": "1.0.0.0",
"target-dir": "JMS/AopBundle",
"time": "2011-12-29 13:50:26",
"time": "2011-12-29 11:50:26",
"source": {
"type": "git",
"url": "https://github.com/schmittjoh/JMSAopBundle",
@ -133,7 +133,7 @@
"version": "1.1.0",
"version_normalized": "1.1.0.0",
"target-dir": "JMS/SecurityExtraBundle",
"time": "2011-12-29 17:38:12",
"time": "2011-12-29 15:38:12",
"source": {
"type": "git",
"url": "https://github.com/schmittjoh/JMSSecurityExtraBundle",
@ -178,7 +178,7 @@
"version": "1.0.1",
"version_normalized": "1.0.1.0",
"target-dir": "JMS/DiExtraBundle",
"time": "2012-02-24 09:01:54",
"time": "2012-02-24 07:01:54",
"source": {
"type": "git",
"url": "https://github.com/schmittjoh/JMSDiExtraBundle",
@ -221,7 +221,7 @@
"name": "doctrine/common",
"version": "2.2.2",
"version_normalized": "2.2.2.0",
"time": "2012-04-06 11:46:44",
"time": "2012-04-06 07:46:44",
"source": {
"type": "git",
"url": "https://github.com/doctrine/common",
@ -287,7 +287,7 @@
"name": "monolog/monolog",
"version": "1.1.0",
"version_normalized": "1.1.0.0",
"time": "2012-04-16 22:27:40",
"time": "2012-04-16 18:27:40",
"source": {
"type": "git",
"url": "https://github.com/Seldaek/monolog.git",
@ -337,7 +337,7 @@
"name": "twig/extensions",
"version": "dev-master",
"version_normalized": "9999999-dev",
"time": "2012-05-15 05:28:19",
"time": "2012-05-15 01:28:19",
"source": {
"type": "git",
"url": "https://github.com/fabpot/Twig-extensions",
@ -383,7 +383,7 @@
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Doctrine/Bundle/DoctrineBundle",
"time": "2012-07-01 18:42:17",
"time": "2012-07-01 14:42:17",
"source": {
"type": "git",
"url": "git://github.com/doctrine/DoctrineBundle.git",
@ -457,7 +457,7 @@
"name": "doctrine/orm",
"version": "2.2.x-dev",
"version_normalized": "2.2.9999999.9999999-dev",
"time": "2012-07-05 15:48:00",
"time": "2012-07-05 11:48:00",
"source": {
"type": "git",
"url": "git://github.com/doctrine/doctrine2.git",
@ -522,7 +522,7 @@
"name": "doctrine/dbal",
"version": "2.2.x-dev",
"version_normalized": "2.2.9999999.9999999-dev",
"time": "2012-07-07 02:30:35",
"time": "2012-07-06 22:30:35",
"source": {
"type": "git",
"url": "https://github.com/doctrine/dbal",
@ -588,7 +588,7 @@
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Sensio/Bundle/GeneratorBundle",
"time": "2012-07-12 08:04:48",
"time": "2012-07-12 04:04:48",
"source": {
"type": "git",
"url": "https://github.com/sensio/SensioGeneratorBundle",
@ -641,7 +641,7 @@
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Symfony/Bundle/MonologBundle",
"time": "2012-06-29 13:48:07",
"time": "2012-06-29 09:48:07",
"source": {
"type": "git",
"url": "https://github.com/symfony/MonologBundle",
@ -701,7 +701,7 @@
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Sensio/Bundle/FrameworkExtraBundle",
"time": "2012-07-11 07:13:52",
"time": "2012-07-11 03:13:52",
"source": {
"type": "git",
"url": "https://github.com/sensio/SensioFrameworkExtraBundle",
@ -750,7 +750,7 @@
"name": "swiftmailer/swiftmailer",
"version": "dev-master",
"version_normalized": "9999999-dev",
"time": "2012-07-12 20:47:17",
"time": "2012-07-12 16:47:17",
"source": {
"type": "git",
"url": "git://github.com/swiftmailer/swiftmailer.git",
@ -806,7 +806,7 @@
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Sensio/Bundle/DistributionBundle",
"time": "2012-07-14 18:24:10",
"time": "2012-07-14 14:24:10",
"source": {
"type": "git",
"url": "https://github.com/sensio/SensioDistributionBundle",
@ -850,7 +850,7 @@
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Symfony/Bundle/SwiftmailerBundle",
"time": "2012-07-19 01:55:12",
"time": "2012-07-18 21:55:12",
"source": {
"type": "git",
"url": "https://github.com/symfony/SwiftmailerBundle",
@ -909,7 +909,7 @@
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Ivory/CKEditorBundle",
"time": "2012-05-28 11:16:47",
"time": "2012-05-28 07:16:47",
"source": {
"type": "git",
"url": "https://github.com/egeloen/IvoryCKEditorBundle",
@ -952,7 +952,7 @@
"name": "kriswallsmith/assetic",
"version": "dev-master",
"version_normalized": "9999999-dev",
"time": "2012-07-20 10:33:33",
"time": "2012-07-20 06:33:33",
"source": {
"type": "git",
"url": "http://github.com/kriswallsmith/assetic.git",
@ -1012,7 +1012,7 @@
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Symfony/Bundle/AsseticBundle",
"time": "2012-07-20 19:34:07",
"time": "2012-07-20 15:34:07",
"source": {
"type": "git",
"url": "https://github.com/symfony/AsseticBundle",
@ -1067,16 +1067,16 @@
"name": "twig/twig",
"version": "dev-master",
"version_normalized": "9999999-dev",
"time": "2012-07-20 12:41:38",
"time": "2012-07-22 08:32:58",
"source": {
"type": "git",
"url": "git://github.com/fabpot/Twig.git",
"reference": "8a84838798e45424c5fe2d87149db6855ae037bf"
"reference": "657de7bdeb680815e0df95f63da9f81e1533d2ea"
},
"dist": {
"type": "zip",
"url": "https://github.com/fabpot/Twig/zipball/8a84838798e45424c5fe2d87149db6855ae037bf",
"reference": "8a84838798e45424c5fe2d87149db6855ae037bf",
"url": "https://github.com/fabpot/Twig/zipball/657de7bdeb680815e0df95f63da9f81e1533d2ea",
"reference": "657de7bdeb680815e0df95f63da9f81e1533d2ea",
"shasum": ""
},
"require": {
@ -1121,22 +1121,22 @@
"name": "symfony/symfony",
"version": "dev-master",
"version_normalized": "9999999-dev",
"time": "2012-07-21 11:16:18",
"time": "2012-07-22 06:03:04",
"source": {
"type": "git",
"url": "git://github.com/symfony/symfony.git",
"reference": "6c256b01b087f94a4ec04487d875fe81375eb6c1"
"reference": "c20c1d18dc0b588e10a8fab24264441f0e4a3e7c"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/symfony/zipball/6c256b01b087f94a4ec04487d875fe81375eb6c1",
"reference": "6c256b01b087f94a4ec04487d875fe81375eb6c1",
"url": "https://github.com/symfony/symfony/zipball/c20c1d18dc0b588e10a8fab24264441f0e4a3e7c",
"reference": "c20c1d18dc0b588e10a8fab24264441f0e4a3e7c",
"shasum": ""
},
"require": {
"twig/twig": ">=1.8,<2.0-dev",
"doctrine/common": ">2.2,<2.4-dev",
"php": ">=5.3.3"
"php": ">=5.3.3",
"twig/twig": ">=1.9.1,<2.0-dev"
},
"replace": {
"symfony/doctrine-bridge": "self.version",

@ -224,30 +224,23 @@
`buildViewBottomUp()` in `FormTypeInterface` and `FormTypeExtensionInterface`.
Furthermore, `buildViewBottomUp()` was renamed to `finishView()`. At last,
all methods in these types now receive instances of `FormBuilderInterface`
and `FormViewInterface` where they received instances of `FormBuilder` and
`FormView` before. You need to change the method signatures in your
form types and extensions as shown below.
where they received instances of `FormBuilder` before. You need to change the
method signatures in your form types and extensions as shown below.
Before:
```
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormView;
public function buildForm(FormBuilder $builder, array $options)
public function buildView(FormView $view, FormInterface $form)
public function buildViewBottomUp(FormView $view, FormInterface $form)
```
After:
```
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormViewInterface;
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
public function finishView(FormViewInterface $view, FormInterface $form, array $options)
```
* The method `createBuilder` was removed from `FormTypeInterface` for performance
@ -383,41 +376,6 @@
If address is an object in this case, the code given in "Before"
works without changes.
* The methods in class `FormView` were renamed to match the naming used in
`Form` and `FormBuilder`. The following list shows the old names on the
left and the new names on the right:
* `set`: `setVar`
* `has`: `hasVar`
* `get`: `getVar`
* `all`: `getVars`
* `addChild`: `add`
* `getChild`: `get`
* `getChildren`: `all`
* `removeChild`: `remove`
* `hasChild`: `has`
The new method `addVars` was added to make the definition of multiple
variables at once more convenient.
The method `hasChildren` was deprecated. You should use `count` instead.
Before:
```
$view->set('help', 'A text longer than six characters');
$view->set('error_class', 'max_length_error');
```
After:
```
$view->addVars(array(
'help' => 'A text longer than six characters',
'error_class' => 'max_length_error',
));
```
* Form and field names must now start with a letter, digit or underscore
and only contain letters, digits, underscores, hyphens and colons.
@ -601,6 +559,22 @@
{% endblock %}
```
* The method `renderBlock()` of the helper for the PHP Templating component was
renamed to `block()`. Its first argument is now expected to be a `FormView`
instance.
Before:
```
<?php echo $view['form']->renderBlock('widget_attributes') ?>
```
After:
```
<?php echo $view['form']->block($form, 'widget_attributes') ?>
```
#### Other BC Breaks
* The order of the first two arguments of the methods `createNamed` and
@ -1054,19 +1028,65 @@
$registry->addType($registry->resolveType(new MyFormType()));
```
* The method `renderBlock()` of the helper for the PHP Templating component was
deprecated and will be removed in Symfony 2.3. You should use `block()` instead.
* The following methods in class `FormView` were deprecated and will be
removed in Symfony 2.3:
* `set`
* `has`
* `get`
* `all`
* `getVars`
* `addChild`
* `getChild`
* `getChildren`
* `removeChild`
* `hasChild`
* `hasChildren`
* `getParent`
* `hasParent`
* `setParent`
You should access the public properties `vars`, `children` and `parent`
instead.
Before:
```
<?php echo $view['form']->renderBlock('widget_attributes') ?>
$view->set('help', 'A text longer than six characters');
$view->set('error_class', 'max_length_error');
```
After:
```
$view->vars = array_replace($view->vars, array(
'help' => 'A text longer than six characters',
'error_class' => 'max_length_error',
));
```
Before:
```
echo $view->get('error_class');
```
After:
```
echo $view->vars['error_class'];
```
Before:
```
if ($view->hasChildren()) { ...
```
After:
```
<?php echo $view['form']->block('widget_attributes') ?>
if (count($view->children)) { ...
```
### Validator

@ -18,7 +18,7 @@
"require": {
"php": ">=5.3.3",
"doctrine/common": ">2.2,<2.4-dev",
"twig/twig": ">=1.8,<2.0-dev"
"twig/twig": ">=1.9.1,<2.0-dev"
},
"replace": {
"symfony/doctrine-bridge": "self.version",

@ -124,7 +124,7 @@ class EntityTypeTest extends TypeTestCase
'property' => 'name'
));
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->getVar('choices'));
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->vars['choices']);
}
public function testSetDataToUninitializedEntityWithNonRequiredToString()
@ -140,7 +140,7 @@ class EntityTypeTest extends TypeTestCase
'required' => false,
));
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->getVar('choices'));
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->vars['choices']);
}
public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
@ -159,7 +159,7 @@ class EntityTypeTest extends TypeTestCase
'query_builder' => $qb
));
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->getVar('choices'));
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->vars['choices']);
}
/**
@ -503,7 +503,7 @@ class EntityTypeTest extends TypeTestCase
$field->bind('2');
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->getVar('choices'));
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->vars['choices']);
$this->assertTrue($field->isSynchronized());
$this->assertSame($entity2, $field->getData());
$this->assertSame('2', $field->getClientData());
@ -533,7 +533,7 @@ class EntityTypeTest extends TypeTestCase
'Group1' => array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')),
'Group2' => array(3 => new ChoiceView('3', 'Baz')),
'4' => new ChoiceView('4', 'Boo!')
), $field->createView()->getVar('choices'));
), $field->createView()->vars['choices']);
}
public function testDisallowChoicesThatAreNotIncluded_choicesSingleIdentifier()

@ -13,7 +13,7 @@ namespace Symfony\Bridge\Twig\Extension;
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
use Symfony\Component\Form\FormViewInterface;
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
/**
@ -62,15 +62,13 @@ class FormExtension extends \Twig_Extension
public function getFunctions()
{
return array(
'form_enctype' => new \Twig_Function_Method($this, 'renderer->renderEnctype', array('is_safe' => array('html'))),
'form_widget' => new \Twig_Function_Method($this, 'renderer->renderWidget', array('is_safe' => array('html'))),
'form_errors' => new \Twig_Function_Method($this, 'renderer->renderErrors', array('is_safe' => array('html'))),
'form_label' => new \Twig_Function_Method($this, 'renderer->renderLabel', array('is_safe' => array('html'))),
'form_row' => new \Twig_Function_Method($this, 'renderer->renderRow', array('is_safe' => array('html'))),
'form_rest' => new \Twig_Function_Method($this, 'renderer->renderRest', array('is_safe' => array('html'))),
'csrf_token' => new \Twig_Function_Method($this, 'renderer->renderCsrfToken'),
'_form_is_choice_group' => new \Twig_Function_Method($this, 'renderer->isChoiceGroup', array('is_safe' => array('html'))),
'_form_is_choice_selected' => new \Twig_Function_Method($this, 'renderer->isChoiceSelected', array('is_safe' => array('html'))),
'form_enctype' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'form_widget' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'form_errors' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'form_label' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'form_row' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'form_rest' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'csrf_token' => new \Twig_Function_Method($this, 'renderer->renderCsrfToken'),
);
}
@ -84,6 +82,48 @@ class FormExtension extends \Twig_Extension
);
}
/**
* {@inheritdoc}
*/
public function getTests()
{
return array(
'selectedchoice' => new \Twig_Test_Method($this, 'isSelectedChoice'),
);
}
/**
* Returns whether a choice is selected for a given form value.
*
* Unfortunately Twig does not support an efficient way to execute the
* "is_selected" closure passed to the template by ChoiceType. It is faster
* to implement the logic here (around 65ms for a specific form).
*
* Directly implementing the logic here is also faster than doing so in
* ChoiceView (around 30ms).
*
* The worst option tested so far is to implement the logic in ChoiceView
* and access the ChoiceView method directly in the template. Doing so is
* around 220ms slower than doing the method call here in the filter. Twig
* seems to be much more efficient at executing filters than at executing
* methods of an object.
*
* @param ChoiceView $choice The choice to check.
* @param string|array $selectedValue The selected value to compare.
*
* @return Boolean Whether the choice is selected.
*
* @see ChoiceView::isSelected()
*/
public function isSelectedChoice(ChoiceView $choice, $selectedValue)
{
if (is_array($selectedValue)) {
return false !== array_search($choice->value, $selectedValue, true);
}
return $choice->value === $selectedValue;
}
/**
* {@inheritdoc}
*/

@ -12,7 +12,7 @@
namespace Symfony\Bridge\Twig\Form;
use Symfony\Component\Form\AbstractRendererEngine;
use Symfony\Component\Form\FormViewInterface;
use Symfony\Component\Form\FormView;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
@ -40,9 +40,9 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
/**
* {@inheritdoc}
*/
public function renderBlock(FormViewInterface $view, $resource, $block, array $variables = array())
public function renderBlock(FormView $view, $resource, $blockName, array $variables = array())
{
$cacheKey = $view->getVar(self::CACHE_KEY_VAR);
$cacheKey = $view->vars[self::CACHE_KEY_VAR];
$context = $this->environment->mergeGlobals($variables);
@ -55,7 +55,7 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
// We do not call renderBlock here to avoid too many nested level calls
// (XDebug limits the level to 100 by default)
$this->template->displayBlock($block, $context, $this->resources[$cacheKey]);
$this->template->displayBlock($blockName, $context, $this->resources[$cacheKey]);
return ob_get_clean();
}
@ -70,13 +70,13 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
*
* @see getResourceForBlock()
*
* @param string $cacheKey The cache key of the form view.
* @param FormViewInterface $view The form view for finding the applying themes.
* @param string $block The name of the block to load.
* @param string $cacheKey The cache key of the form view.
* @param FormView $view The form view for finding the applying themes.
* @param string $blockName The name of the block to load.
*
* @return Boolean True if the resource could be loaded, false otherwise.
*/
protected function loadResourceForBlock($cacheKey, FormViewInterface $view, $block)
protected function loadResourceForBlockName($cacheKey, FormView $view, $blockName)
{
// The caller guarantees that $this->resources[$cacheKey][$block] is
// not set, but it doesn't have to check whether $this->resources[$cacheKey]
@ -86,7 +86,7 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
// As said in the previous, the caller guarantees that
// $this->resources[$cacheKey][$block] is not set. Since the themes are
// already loaded, it can only be a non-existing block.
$this->resources[$cacheKey][$block] = false;
$this->resources[$cacheKey][$blockName] = false;
return false;
}
@ -105,7 +105,7 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
}
// Check the default themes once we reach the root view without success
if (!$view->hasParent()) {
if (!$view->parent) {
for ($i = count($this->defaultThemes) - 1; $i >= 0; --$i) {
$this->loadResourcesFromTheme($cacheKey, $this->defaultThemes[$i]);
// CONTINUE LOADING (see doc comment)
@ -113,29 +113,29 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
}
// Proceed with the themes of the parent view
if ($view->hasParent()) {
$parentCacheKey = $view->getParent()->getVar(self::CACHE_KEY_VAR);
if ($view->parent) {
$parentCacheKey = $view->parent->vars[self::CACHE_KEY_VAR];
if (!isset($this->resources[$parentCacheKey])) {
$this->loadResourceForBlock($parentCacheKey, $view->getParent(), $block);
$this->loadResourceForBlockName($parentCacheKey, $view->parent, $blockName);
}
// EAGER CACHE POPULATION (see doc comment)
foreach ($this->resources[$parentCacheKey] as $blockName => $resource) {
if (!isset($this->resources[$cacheKey][$blockName])) {
$this->resources[$cacheKey][$blockName] = $resource;
foreach ($this->resources[$parentCacheKey] as $nestedBlockName => $resource) {
if (!isset($this->resources[$cacheKey][$nestedBlockName])) {
$this->resources[$cacheKey][$nestedBlockName] = $resource;
}
}
}
// Even though we loaded the themes, it can happen that none of them
// contains the searched block
if (!isset($this->resources[$cacheKey][$block])) {
if (!isset($this->resources[$cacheKey][$blockName])) {
// Cache that we didn't find anything to speed up further accesses
$this->resources[$cacheKey][$block] = false;
$this->resources[$cacheKey][$blockName] = false;
}
return false !== $this->resources[$cacheKey][$block];
return false !== $this->resources[$cacheKey][$blockName];
}
/**

@ -0,0 +1,56 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\Twig\Node;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class SearchAndRenderBlockNode extends \Twig_Node_Expression_Function
{
public function compile(\Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
$compiler->raw('$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(');
preg_match('/_([^_]+)$/', $this->getAttribute('name'), $matches);
$label = null;
$arguments = iterator_to_array($this->getNode('arguments'));
$blockNameSuffix = $matches[1];
if (isset($arguments[0])) {
$compiler->subcompile($arguments[0]);
$compiler->raw(', \'' . $blockNameSuffix . '\'');
if (isset($arguments[1])) {
$compiler->raw(', ');
// The "label" function allows one extra argument here, the label
if ('label' === $blockNameSuffix) {
if (isset($arguments[2])) {
$compiler->subcompile($arguments[2]);
$compiler->raw(' + ');
}
// Add the label to the variable array
$compiler->raw('array(\'label\' => ');
$compiler->subcompile($arguments[1]);
$compiler->raw(')');
} else {
$compiler->subcompile($arguments[1]);
}
}
}
$compiler->raw(")");
}
}

@ -86,15 +86,14 @@
{% block choice_widget_options %}
{% spaceless %}
{% for index, choice in options %}
{% if _form_is_choice_group(choice) %}
<optgroup label="{{ index|trans({}, translation_domain) }}">
{% for nested_choice in choice %}
<option value="{{ nested_choice.value }}"{% if _form_is_choice_selected(form, nested_choice) %} selected="selected"{% endif %}>{{ nested_choice.label|trans({}, translation_domain) }}</option>
{% endfor %}
{% for group_label, choice in options %}
{% if choice is iterable %}
<optgroup label="{{ group_label|trans({}, translation_domain) }}">
{% set options = choice %}
{{ block('choice_widget_options') }}
</optgroup>
{% else %}
<option value="{{ choice.value }}"{% if _form_is_choice_selected(form, choice) %} selected="selected"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option>
<option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option>
{% endif %}
{% endfor %}
{% endspaceless %}

@ -18,6 +18,7 @@ use Symfony\Bridge\Twig\Extension\TranslationExtension;
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
use Symfony\Component\Form\Tests\AbstractDivLayoutTest;
class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
@ -105,34 +106,71 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
);
}
public function isSelectedChoiceProvider()
{
// The commented cases should not be necessary anymore, because the
// choice lists should assure that both values passed here are always
// strings
return array(
// array(true, 0, 0),
array(true, '0', '0'),
array(true, '1', '1'),
// array(true, false, 0),
// array(true, true, 1),
array(true, '', ''),
// array(true, null, ''),
array(true, '1.23', '1.23'),
array(true, 'foo', 'foo'),
array(true, 'foo10', 'foo10'),
array(true, 'foo', array(1, 'foo', 'foo10')),
array(false, 10, array(1, 'foo', 'foo10')),
array(false, 0, array(1, 'foo', 'foo10')),
);
}
/**
* @dataProvider isSelectedChoiceProvider
*/
public function testIsChoiceSelected($expected, $choice, $value)
{
$choice = new ChoiceView($choice, $choice . ' label');
$this->assertSame($expected, $this->extension->isSelectedChoice($choice, $value));
}
protected function renderEnctype(FormView $view)
{
return (string) $this->extension->renderer->renderEnctype($view);
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'enctype');
}
protected function renderLabel(FormView $view, $label = null, array $vars = array())
{
return (string) $this->extension->renderer->renderLabel($view, $label, $vars);
if ($label !== null) {
$vars += array('label' => $label);
}
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'label', $vars);
}
protected function renderErrors(FormView $view)
{
return (string) $this->extension->renderer->renderErrors($view);
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'errors');
}
protected function renderWidget(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->renderWidget($view, $vars);
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'widget', $vars);
}
protected function renderRow(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->renderRow($view, $vars);
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'row', $vars);
}
protected function renderRest(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->renderRest($view, $vars);
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'rest', $vars);
}
protected function setTheme(FormView $view, array $themes)

@ -77,32 +77,36 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
protected function renderEnctype(FormView $view)
{
return (string) $this->extension->renderer->renderEnctype($view);
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'enctype');
}
protected function renderLabel(FormView $view, $label = null, array $vars = array())
{
return (string) $this->extension->renderer->renderLabel($view, $label, $vars);
if ($label !== null) {
$vars += array('label' => $label);
}
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'label', $vars);
}
protected function renderErrors(FormView $view)
{
return (string) $this->extension->renderer->renderErrors($view);
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'errors');
}
protected function renderWidget(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->renderWidget($view, $vars);
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'widget', $vars);
}
protected function renderRow(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->renderRow($view, $vars);
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'row', $vars);
}
protected function renderRest(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->renderRest($view, $vars);
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'rest', $vars);
}
protected function setTheme(FormView $view, array $themes)

@ -17,7 +17,7 @@
],
"require": {
"php": ">=5.3.3",
"twig/twig": ">=1.8,<2.0-dev"
"twig/twig": ">=1.9.1,<2.0-dev"
},
"require-dev": {
"symfony/form": "2.1.*",

@ -1 +1 @@
<?php echo $view['form']->block('widget_attributes') ?>
<?php echo $view['form']->block($form, 'widget_attributes') ?>

@ -1,5 +1,5 @@
<input type="checkbox"
<?php echo $view['form']->block('widget_attributes') ?>
<?php echo $view['form']->block($form, 'widget_attributes') ?>
<?php if ($value): ?> value="<?php echo $view->escape($value) ?>"<?php endif ?>
<?php if ($checked): ?> checked="checked"<?php endif ?>
/>

@ -1 +1 @@
<?php echo $view['form']->block('choice_widget_options') ?>
<?php echo $view['form']->block($form, 'choice_widget_options') ?>

@ -1,5 +1,5 @@
<?php if ($expanded): ?>
<?php echo $view['form']->block('choice_widget_expanded') ?>
<?php echo $view['form']->block($form, 'choice_widget_expanded') ?>
<?php else: ?>
<?php echo $view['form']->block('choice_widget_collapsed') ?>
<?php echo $view['form']->block($form, 'choice_widget_collapsed') ?>
<?php endif ?>

@ -1,13 +1,13 @@
<select
<?php echo $view['form']->block('widget_attributes') ?>
<?php echo $view['form']->block($form, 'widget_attributes') ?>
<?php if ($multiple): ?> multiple="multiple"<?php endif ?>
>
<?php if (null !== $empty_value): ?><option value=""><?php echo $view->escape($view['translator']->trans($empty_value, array(), $translation_domain)) ?></option><?php endif; ?>
<?php if (count($preferred_choices) > 0): ?>
<?php echo $view['form']->block('choice_widget_options', array('options' => $preferred_choices)) ?>
<?php echo $view['form']->block($form, 'choice_widget_options', array('choices' => $preferred_choices)) ?>
<?php if (count($choices) > 0 && null !== $separator): ?>
<option disabled="disabled"><?php echo $separator ?></option>
<?php endif ?>
<?php endif ?>
<?php echo $view['form']->block('choice_widget_options', array('options' => $choices)) ?>
<?php echo $view['form']->block($form, 'choice_widget_options', array('choices' => $choices)) ?>
</select>

@ -1,4 +1,4 @@
<div <?php echo $view['form']->block('widget_container_attributes') ?>>
<div <?php echo $view['form']->block($form, 'widget_container_attributes') ?>>
<?php foreach ($form as $child): ?>
<?php echo $view['form']->widget($child) ?>
<?php echo $view['form']->label($child) ?>

@ -1,11 +1,11 @@
<?php foreach ($options as $index => $choice): ?>
<?php if ($view['form']->isChoiceGroup($choice)): ?>
<optgroup label="<?php echo $view->escape($view['translator']->trans($index, array(), $translation_domain)) ?>">
<?php foreach ($choice as $nested_choice): ?>
<option value="<?php echo $view->escape($nested_choice->getValue()) ?>"<?php if ($view['form']->isChoiceSelected($form, $nested_choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($view['translator']->trans($nested_choice->getLabel(), array(), $translation_domain)) ?></option>
<?php endforeach ?>
<?php $translatorHelper = $view['translator']; // outside of the loop for performance reasons! ?>
<?php $formHelper = $view['form']; ?>
<?php foreach ($choices as $index => $choice): ?>
<?php if (is_array($choice)): ?>
<optgroup label="<?php echo $view->escape($translatorHelper->trans($index, array(), $translation_domain)) ?>">
<?php echo $formHelper->block($form, 'choice_widget_options', array('choices' => $choice)) ?>
</optgroup>
<?php else: ?>
<option value="<?php echo $view->escape($choice->getValue()) ?>"<?php if ($view['form']->isChoiceSelected($form, $choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($view['translator']->trans($choice->getLabel(), array(), $translation_domain)) ?></option>
<option value="<?php echo $view->escape($choice->value) ?>"<?php if ($is_selected($choice->value, $value)): ?> selected="selected"<?php endif?>><?php echo $view->escape($translatorHelper->trans($choice->label, array(), $translation_domain)) ?></option>
<?php endif ?>
<?php endforeach ?>

@ -1 +1 @@
<?php echo $view['form']->block('widget_container_attributes') ?>
<?php echo $view['form']->block($form, 'widget_container_attributes') ?>

@ -1,7 +1,7 @@
<?php if ($widget == 'single_text'): ?>
<?php echo $view['form']->block('form_widget_simple'); ?>
<?php echo $view['form']->block($form, 'form_widget_simple'); ?>
<?php else: ?>
<div <?php echo $view['form']->block('widget_container_attributes') ?>>
<div <?php echo $view['form']->block($form, 'widget_container_attributes') ?>>
<?php echo str_replace(array('{{ year }}', '{{ month }}', '{{ day }}'), array(
$view['form']->widget($form['year']),
$view['form']->widget($form['month']),

@ -1,7 +1,7 @@
<?php if ($widget == 'single_text'): ?>
<?php echo $view['form']->block('form_widget_simple'); ?>
<?php echo $view['form']->block($form, 'form_widget_simple'); ?>
<?php else: ?>
<div <?php echo $view['form']->block('widget_container_attributes') ?>>
<div <?php echo $view['form']->block($form, 'widget_container_attributes') ?>>
<?php echo $view['form']->widget($form['date']).' '.$view['form']->widget($form['time']) ?>
</div>
<?php endif ?>

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple', array('type' => isset($type) ? $type : 'email')) ?>
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'email')) ?>

@ -1 +1 @@
<?php echo $view['form']->block('form_enctype') ?>
<?php echo $view['form']->block($form, 'form_enctype') ?>

@ -1 +1 @@
<?php echo $view['form']->block('form_errors') ?>
<?php echo $view['form']->block($form, 'form_errors') ?>

@ -1 +1 @@
<?php echo $view['form']->block('form_label') ?>
<?php echo $view['form']->block($form, 'form_label') ?>

@ -1 +1 @@
<?php echo $view['form']->block('form_rest') ?>
<?php echo $view['form']->block($form, 'form_rest') ?>

@ -1 +1 @@
<?php echo $view['form']->block('form_row') ?>
<?php echo $view['form']->block($form, 'form_row') ?>

@ -1 +1 @@
<?php echo $view['form']->block('form_rows') ?>
<?php echo $view['form']->block($form, 'form_rows') ?>

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple') ?>
<?php echo $view['form']->block($form, 'form_widget_simple') ?>

@ -1 +1 @@
<?php if ($form->getVar('multipart')): ?>enctype="multipart/form-data"<?php endif ?>
<?php if ($form->vars['multipart']): ?>enctype="multipart/form-data"<?php endif ?>

@ -1,5 +1,5 @@
<?php if ($compound): ?>
<?php echo $view['form']->block('form_widget_compound')?>
<?php echo $view['form']->block($form, 'form_widget_compound')?>
<?php else: ?>
<?php echo $view['form']->block('form_widget_simple')?>
<?php echo $view['form']->block($form, 'form_widget_simple')?>
<?php endif ?>

@ -1,11 +1,11 @@
<div <?php echo $view['form']->block('widget_container_attributes') ?>>
<?php if (!$form->hasParent() && $errors): ?>
<div <?php echo $view['form']->block($form, 'widget_container_attributes') ?>>
<?php if (!$form->parent && $errors): ?>
<tr>
<td colspan="2">
<?php echo $view['form']->errors($form) ?>
</td>
</tr>
<?php endif ?>
<?php echo $view['form']->block('form_rows') ?>
<?php echo $view['form']->block($form, 'form_rows') ?>
<?php echo $view['form']->rest($form) ?>
</div>

@ -1,5 +1,5 @@
<input
type="<?php echo isset($type) ? $view->escape($type) : 'text' ?>"
<?php if (!empty($value)): ?>value="<?php echo $view->escape($value) ?>"<?php endif ?>
<?php echo $view['form']->block('widget_attributes') ?>
<?php echo $view['form']->block($form, 'widget_attributes') ?>
/>

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple', array('type' => isset($type) ? $type : "hidden")) ?>
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "hidden")) ?>

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple', array('type' => isset($type) ? $type : "number")) ?>
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "number")) ?>

@ -1 +1 @@
<?php echo str_replace('{{ widget }}', $view['form']->block('form_widget_simple'), $money_pattern) ?>
<?php echo str_replace('{{ widget }}', $view['form']->block($form, 'form_widget_simple'), $money_pattern) ?>

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple', array('type' => isset($type) ? $type : "text")) ?>
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "text")) ?>

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple', array('type' => isset($type) ? $type : "password")) ?>
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "password")) ?>

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple', array('type' => isset($type) ? $type : "text")) ?> %
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "text")) ?> %

@ -1,5 +1,5 @@
<input type="radio"
<?php echo $view['form']->block('widget_attributes') ?>
<?php echo $view['form']->block($form, 'widget_attributes') ?>
value="<?php echo $view->escape($value) ?>"
<?php if ($checked): ?> checked="checked"<?php endif ?>
/>

@ -1 +1 @@
<?php echo $view['form']->block('form_rows') ?>
<?php echo $view['form']->block($form, 'form_rows') ?>

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple', array('type' => isset($type) ? $type : "search")) ?>
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "search")) ?>

@ -1 +1 @@
<textarea <?php echo $view['form']->block('widget_attributes') ?>><?php echo $view->escape($value) ?></textarea>
<textarea <?php echo $view['form']->block($form, 'widget_attributes') ?>><?php echo $view->escape($value) ?></textarea>

@ -1,7 +1,7 @@
<?php if ($widget == 'single_text'): ?>
<?php echo $view['form']->block('form_widget_simple'); ?>
<?php echo $view['form']->block($form, 'form_widget_simple'); ?>
<?php else: ?>
<div <?php echo $view['form']->block('widget_container_attributes') ?>>
<div <?php echo $view['form']->block($form, 'widget_container_attributes') ?>>
<?php
// There should be no spaces between the colons and the widgets, that's why
// this block is written in a single PHP tag

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple', array('type' => isset($type) ? $type : "url")) ?>
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "url")) ?>

@ -1,7 +1,7 @@
<table <?php echo $view['form']->block('widget_container_attributes') ?>>
<?php if (!$form->hasParent()): ?>
<table <?php echo $view['form']->block($form, 'widget_container_attributes') ?>>
<?php if (!$form->parent): ?>
<?php echo $view['form']->errors($form) ?>
<?php endif ?>
<?php echo $view['form']->block('form_rows') ?>
<?php echo $view['form']->block($form, 'form_rows') ?>
<?php echo $view['form']->rest($form) ?>
</table>

@ -13,7 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Templating\Helper;
use Symfony\Component\Templating\Helper\Helper;
use Symfony\Component\Form\FormRendererInterface;
use Symfony\Component\Form\FormViewInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
@ -49,25 +49,15 @@ class FormHelper extends Helper
return 'form';
}
public function isChoiceGroup($label)
{
return $this->renderer->isChoiceGroup($label);
}
public function isChoiceSelected(FormViewInterface $view, ChoiceView $choice)
{
return $this->renderer->isChoiceSelected($view, $choice);
}
/**
* Sets a theme for a given view.
*
* The theme format is "<Bundle>:<Controller>".
*
* @param FormViewInterface $view A FormViewInterface instance
* @param FormView $view A FormView instance
* @param string|array $themes A theme or an array of theme
*/
public function setTheme(FormViewInterface $view, $themes)
public function setTheme(FormView $view, $themes)
{
$this->renderer->setTheme($view, $themes);
}
@ -79,13 +69,13 @@ class FormHelper extends Helper
*
* <form action="..." method="post" <?php echo $view['form']->enctype() ?>>
*
* @param FormViewInterface $view The view for which to render the encoding type
* @param FormView $view The view for which to render the encoding type
*
* @return string The HTML markup
*/
public function enctype(FormViewInterface $view)
public function enctype(FormView $view)
{
return $this->renderer->renderEnctype($view);
return $this->renderer->searchAndRenderBlock($view, 'enctype');
}
/**
@ -101,95 +91,84 @@ class FormHelper extends Helper
*
* <?php echo view['form']->widget(array('separator' => '+++++)) ?>
*
* @param FormViewInterface $view The view for which to render the widget
* @param array $variables Additional variables passed to the template
* @param FormView $view The view for which to render the widget
* @param array $variables Additional variables passed to the template
*
* @return string The HTML markup
*/
public function widget(FormViewInterface $view, array $variables = array())
public function widget(FormView $view, array $variables = array())
{
return $this->renderer->renderWidget($view, $variables);
return $this->renderer->searchAndRenderBlock($view, 'widget', $variables);
}
/**
* Renders the entire form field "row".
*
* @param FormViewInterface $view The view for which to render the row
* @param array $variables Additional variables passed to the template
* @param FormView $view The view for which to render the row
* @param array $variables Additional variables passed to the template
*
* @return string The HTML markup
*/
public function row(FormViewInterface $view, array $variables = array())
public function row(FormView $view, array $variables = array())
{
return $this->renderer->renderRow($view, $variables);
return $this->renderer->searchAndRenderBlock($view, 'row', $variables);
}
/**
* Renders the label of the given view.
*
* @param FormViewInterface $view The view for which to render the label
* @param string $label The label
* @param array $variables Additional variables passed to the template
* @param FormView $view The view for which to render the label
* @param string $label The label
* @param array $variables Additional variables passed to the template
*
* @return string The HTML markup
*/
public function label(FormViewInterface $view, $label = null, array $variables = array())
public function label(FormView $view, $label = null, array $variables = array())
{
return $this->renderer->renderLabel($view, $label, $variables);
if ($label !== null) {
$variables += array('label' => $label);
}
return $this->renderer->searchAndRenderBlock($view, 'label', $variables);
}
/**
* Renders the errors of the given view.
*
* @param FormViewInterface $view The view to render the errors for
* @param FormView $view The view to render the errors for
*
* @return string The HTML markup
*/
public function errors(FormViewInterface $view)
public function errors(FormView $view)
{
return $this->renderer->renderErrors($view);
return $this->renderer->searchAndRenderBlock($view, 'errors');
}
/**
* Renders views which have not already been rendered.
*
* @param FormViewInterface $view The parent view
* @param array $variables An array of variables
*
* @return string The HTML markup
*/