Skip to content

Commit 0399d9e

Browse files
Merge branch '3.4'
* 3.4: Fix phpunit bridge [Form] [TwigBridge] Added option to disable usage of default themes when rendering a form
2 parents 9005c6a + b346199 commit 0399d9e

File tree

7 files changed

+32
-15
lines changed

7 files changed

+32
-15
lines changed

AbstractRendererEngine.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ abstract class AbstractRendererEngine implements FormRendererEngineInterface
3333
*/
3434
protected $themes = array();
3535

36+
/**
37+
* @var array
38+
*/
39+
protected $useDefaultThemes = array();
40+
3641
/**
3742
* @var array
3843
*/
@@ -57,13 +62,16 @@ public function __construct(array $defaultThemes = array())
5762
/**
5863
* {@inheritdoc}
5964
*/
60-
public function setTheme(FormView $view, $themes)
65+
public function setTheme(FormView $view, $themes /*, $useDefaultThemes = true */)
6166
{
6267
$cacheKey = $view->vars[self::CACHE_KEY_VAR];
6368

6469
// Do not cast, as casting turns objects into arrays of properties
6570
$this->themes[$cacheKey] = is_array($themes) ? $themes : array($themes);
6671

72+
$args = func_get_args();
73+
$this->useDefaultThemes[$cacheKey] = isset($args[2]) ? (bool) $args[2] : true;
74+
6775
// Unset instead of resetting to an empty array, in order to allow
6876
// implementations (like TwigRendererEngine) to check whether $cacheKey
6977
// is set at all.

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ CHANGELOG
2626
* added `DebugCommand`
2727
* deprecated `ChoiceLoaderInterface` implementation in `TimezoneType`
2828
* added options "input" and "regions" to `TimezoneType`
29+
* added an option to ``Symfony\Component\Form\FormRendererEngineInterface::setTheme()`` and
30+
``Symfony\Component\Form\FormRendererInterface::setTheme()`` to disable usage of default themes when rendering a form
2931

3032
3.3.0
3133
-----

Extension/Templating/TemplatingRendererEngine.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ protected function loadResourceForBlockName($cacheKey, FormView $view, $blockNam
7272

7373
// Check the default themes once we reach the root form without success
7474
if (!$view->parent) {
75-
for ($i = count($this->defaultThemes) - 1; $i >= 0; --$i) {
76-
if ($this->loadResourceFromTheme($cacheKey, $blockName, $this->defaultThemes[$i])) {
77-
return true;
75+
if (!isset($this->useDefaultThemes[$cacheKey]) || $this->useDefaultThemes[$cacheKey]) {
76+
for ($i = count($this->defaultThemes) - 1; $i >= 0; --$i) {
77+
if ($this->loadResourceFromTheme($cacheKey, $blockName, $this->defaultThemes[$i])) {
78+
return true;
79+
}
7880
}
7981
}
8082
}

FormRenderer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ public function getEngine()
7070
/**
7171
* {@inheritdoc}
7272
*/
73-
public function setTheme(FormView $view, $themes)
73+
public function setTheme(FormView $view, $themes /*, $useDefaultThemes = true */)
7474
{
75-
$this->engine->setTheme($view, $themes);
75+
$args = func_get_args();
76+
$this->engine->setTheme($view, $themes, isset($args[2]) ? (bool) $args[2] : true);
7677
}
7778

7879
/**

FormRendererEngineInterface.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ interface FormRendererEngineInterface
2121
/**
2222
* Sets the theme(s) to be used for rendering a view and its children.
2323
*
24-
* @param FormView $view The view to assign the theme(s) to
25-
* @param mixed $themes The theme(s). The type of these themes
26-
* is open to the implementation.
24+
* @param FormView $view The view to assign the theme(s) to
25+
* @param mixed $themes The theme(s). The type of these themes
26+
* is open to the implementation.
27+
* @param bool $useDefaultThemes If true, will use default themes specified
28+
* in the engine, will be added to the interface in 4.0
2729
*/
28-
public function setTheme(FormView $view, $themes);
30+
public function setTheme(FormView $view, $themes /*, $useDefaultThemes = true */);
2931

3032
/**
3133
* Returns the resource for a block name.

FormRendererInterface.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ public function getEngine();
2828
/**
2929
* Sets the theme(s) to be used for rendering a view and its children.
3030
*
31-
* @param FormView $view The view to assign the theme(s) to
32-
* @param mixed $themes The theme(s). The type of these themes
33-
* is open to the implementation.
31+
* @param FormView $view The view to assign the theme(s) to
32+
* @param mixed $themes The theme(s). The type of these themes
33+
* is open to the implementation.
34+
* @param bool $useDefaultThemes If true, will use default themes specified
35+
* in the renderer, will be added to the interface in 4.0
3436
*/
35-
public function setTheme(FormView $view, $themes);
37+
public function setTheme(FormView $view, $themes /*, $useDefaultThemes = true */);
3638

3739
/**
3840
* Renders a named block of the form theme.

Tests/AbstractLayoutTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ abstract protected function renderStart(FormView $view, array $vars = array());
125125

126126
abstract protected function renderEnd(FormView $view, array $vars = array());
127127

128-
abstract protected function setTheme(FormView $view, array $themes);
128+
abstract protected function setTheme(FormView $view, array $themes, $useDefaultThemes = true);
129129

130130
public function testLabel()
131131
{

0 commit comments

Comments
 (0)