From 9f77cabd2fef2bbefa83a73312f94e297d74d8e0 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Tue, 8 Feb 2011 16:41:15 -0500 Subject: [PATCH] [TwigBundle] Cast non-array resources argument to array in form_field() twig function Methods within FormExtension later type-hint this parameter as an array, but it's convenient to allow a single string to be passed from Twig if we ensure it's wrapped in an array. --- .../Bundle/TwigBundle/Extension/FormExtension.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/Extension/FormExtension.php b/src/Symfony/Bundle/TwigBundle/Extension/FormExtension.php index aab5c28c556e..4f96e842111b 100644 --- a/src/Symfony/Bundle/TwigBundle/Extension/FormExtension.php +++ b/src/Symfony/Bundle/TwigBundle/Extension/FormExtension.php @@ -123,12 +123,17 @@ public function renderRow(FieldInterface $field) * * {{ form_field(field, {}, {'separator': '+++++'}) }} * - * @param FieldInterface $field The field to render - * @param array $params Additional variables passed to the template - * @param string $resources + * @param FieldInterface $field The field to render + * @param array $attributes HTML attributes passed to the template + * @param array $parameters Additional variables passed to the template + * @param array|string $resources A resource or array of resources */ public function renderField(FieldInterface $field, array $attributes = array(), array $parameters = array(), $resources = null) { + if (null !== $resources && !is_array($resources)) { + $resources = array($resources); + } + return $this->render($field, 'field', array( 'field' => $field, 'attr' => $attributes, @@ -190,7 +195,7 @@ public function renderData(FieldInterface $field) return $field->getData(); } - protected function render(FieldInterface $field, $name, array $arguments, $resources = null) + protected function render(FieldInterface $field, $name, array $arguments, array $resources = null) { if ('field' === $name) { list($name, $template) = $this->getWidget($field, $resources);