Permalink
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
  • Loading branch information...
2 parents 9005c6a + b346199 commit 0399d9e0885bfa4774fd5df17207f1ede5745cd1 @nicolas-grekas nicolas-grekas committed Oct 13, 2017
View
@@ -36,6 +36,11 @@
/**
* @var array
*/
+ protected $useDefaultThemes = array();
+
+ /**
+ * @var array
+ */
protected $resources = array();
/**
@@ -57,13 +62,16 @@ public function __construct(array $defaultThemes = array())
/**
* {@inheritdoc}
*/
- public function setTheme(FormView $view, $themes)
+ public function setTheme(FormView $view, $themes /*, $useDefaultThemes = true */)
{
$cacheKey = $view->vars[self::CACHE_KEY_VAR];
// Do not cast, as casting turns objects into arrays of properties
$this->themes[$cacheKey] = is_array($themes) ? $themes : array($themes);
+ $args = func_get_args();
+ $this->useDefaultThemes[$cacheKey] = isset($args[2]) ? (bool) $args[2] : true;
+
// Unset instead of resetting to an empty array, in order to allow
// implementations (like TwigRendererEngine) to check whether $cacheKey
// is set at all.
View
@@ -26,6 +26,8 @@ CHANGELOG
* added `DebugCommand`
* deprecated `ChoiceLoaderInterface` implementation in `TimezoneType`
* added options "input" and "regions" to `TimezoneType`
+ * added an option to ``Symfony\Component\Form\FormRendererEngineInterface::setTheme()`` and
+ ``Symfony\Component\Form\FormRendererInterface::setTheme()`` to disable usage of default themes when rendering a form
3.3.0
-----
@@ -72,9 +72,11 @@ protected function loadResourceForBlockName($cacheKey, FormView $view, $blockNam
// Check the default themes once we reach the root form without success
if (!$view->parent) {
- for ($i = count($this->defaultThemes) - 1; $i >= 0; --$i) {
- if ($this->loadResourceFromTheme($cacheKey, $blockName, $this->defaultThemes[$i])) {
- return true;
+ if (!isset($this->useDefaultThemes[$cacheKey]) || $this->useDefaultThemes[$cacheKey]) {
+ for ($i = count($this->defaultThemes) - 1; $i >= 0; --$i) {
+ if ($this->loadResourceFromTheme($cacheKey, $blockName, $this->defaultThemes[$i])) {
+ return true;
+ }
}
}
}
View
@@ -70,9 +70,10 @@ public function getEngine()
/**
* {@inheritdoc}
*/
- public function setTheme(FormView $view, $themes)
+ public function setTheme(FormView $view, $themes /*, $useDefaultThemes = true */)
{
- $this->engine->setTheme($view, $themes);
+ $args = func_get_args();
+ $this->engine->setTheme($view, $themes, isset($args[2]) ? (bool) $args[2] : true);
}
/**
@@ -21,11 +21,13 @@
/**
* Sets the theme(s) to be used for rendering a view and its children.
*
- * @param FormView $view The view to assign the theme(s) to
- * @param mixed $themes The theme(s). The type of these themes
- * is open to the implementation.
+ * @param FormView $view The view to assign the theme(s) to
+ * @param mixed $themes The theme(s). The type of these themes
+ * is open to the implementation.
+ * @param bool $useDefaultThemes If true, will use default themes specified
+ * in the engine, will be added to the interface in 4.0
*/
- public function setTheme(FormView $view, $themes);
+ public function setTheme(FormView $view, $themes /*, $useDefaultThemes = true */);
/**
* Returns the resource for a block name.
View
@@ -28,11 +28,13 @@ public function getEngine();
/**
* Sets the theme(s) to be used for rendering a view and its children.
*
- * @param FormView $view The view to assign the theme(s) to
- * @param mixed $themes The theme(s). The type of these themes
- * is open to the implementation.
+ * @param FormView $view The view to assign the theme(s) to
+ * @param mixed $themes The theme(s). The type of these themes
+ * is open to the implementation.
+ * @param bool $useDefaultThemes If true, will use default themes specified
+ * in the renderer, will be added to the interface in 4.0
*/
- public function setTheme(FormView $view, $themes);
+ public function setTheme(FormView $view, $themes /*, $useDefaultThemes = true */);
/**
* Renders a named block of the form theme.
@@ -125,7 +125,7 @@ protected function assertWidgetMatchesXpath(FormView $view, array $vars, $xpath)
abstract protected function renderEnd(FormView $view, array $vars = array());
- abstract protected function setTheme(FormView $view, array $themes);
+ abstract protected function setTheme(FormView $view, array $themes, $useDefaultThemes = true);
public function testLabel()
{

0 comments on commit 0399d9e

Please sign in to comment.