Skip to content
Browse files

[Form] Improved FormRenderer API to reduce the size of the function c…

…all stack during rendering
  • Loading branch information...
1 parent ec4250a commit 0628f2f2dd8a905ec554f100bafae403ad9d2c97 @webmozart webmozart committed Jul 21, 2012
View
86 AbstractRendererEngine.php
@@ -74,132 +74,132 @@ public function setTheme(FormView $view, $themes)
/**
* {@inheritdoc}
*/
- public function getResourceForBlock(FormView $view, $block)
+ public function getResourceForBlockName(FormView $view, $blockName)
{
$cacheKey = $view->vars[self::CACHE_KEY_VAR];
- if (!isset($this->resources[$cacheKey][$block])) {
- $this->loadResourceForBlock($cacheKey, $view, $block);
+ if (!isset($this->resources[$cacheKey][$blockName])) {
+ $this->loadResourceForBlockName($cacheKey, $view, $blockName);
}
- return $this->resources[$cacheKey][$block];
+ return $this->resources[$cacheKey][$blockName];
}
/**
* {@inheritdoc}
*/
- public function getResourceForBlockHierarchy(FormView $view, array $blockHierarchy, $hierarchyLevel)
+ public function getResourceForBlockNameHierarchy(FormView $view, array $blockNameHierarchy, $hierarchyLevel)
{
$cacheKey = $view->vars[self::CACHE_KEY_VAR];
- $block = $blockHierarchy[$hierarchyLevel];
+ $blockName = $blockNameHierarchy[$hierarchyLevel];
- if (!isset($this->resources[$cacheKey][$block])) {
- $this->loadResourceForBlockHierarchy($cacheKey, $view, $blockHierarchy, $hierarchyLevel);
+ if (!isset($this->resources[$cacheKey][$blockName])) {
+ $this->loadResourceForBlockNameHierarchy($cacheKey, $view, $blockNameHierarchy, $hierarchyLevel);
}
- return $this->resources[$cacheKey][$block];
+ return $this->resources[$cacheKey][$blockName];
}
/**
* {@inheritdoc}
*/
- public function getResourceHierarchyLevel(FormView $view, array $blockHierarchy, $hierarchyLevel)
+ public function getResourceHierarchyLevel(FormView $view, array $blockNameHierarchy, $hierarchyLevel)
{
$cacheKey = $view->vars[self::CACHE_KEY_VAR];
- $block = $blockHierarchy[$hierarchyLevel];
+ $blockName = $blockNameHierarchy[$hierarchyLevel];
- if (!isset($this->resources[$cacheKey][$block])) {
- $this->loadResourceForBlockHierarchy($cacheKey, $view, $blockHierarchy, $hierarchyLevel);
+ if (!isset($this->resources[$cacheKey][$blockName])) {
+ $this->loadResourceForBlockNameHierarchy($cacheKey, $view, $blockNameHierarchy, $hierarchyLevel);
}
// If $block was previously rendered loaded with loadTemplateForBlock(), the template
// is cached but the hierarchy level is not. In this case, we know that the block
// exists at this very hierarchy level, so we can just set it.
- if (!isset($this->resourceHierarchyLevels[$cacheKey][$block])) {
- $this->resourceHierarchyLevels[$cacheKey][$block] = $hierarchyLevel;
+ if (!isset($this->resourceHierarchyLevels[$cacheKey][$blockName])) {
+ $this->resourceHierarchyLevels[$cacheKey][$blockName] = $hierarchyLevel;
}
- return $this->resourceHierarchyLevels[$cacheKey][$block];
+ return $this->resourceHierarchyLevels[$cacheKey][$blockName];
}
/**
* Loads the cache with the resource for a given block name.
*
* @see getResourceForBlock()
*
- * @param string $cacheKey The cache key of the form view.
- * @param FormView $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.
*/
- abstract protected function loadResourceForBlock($cacheKey, FormView $view, $block);
+ abstract protected function loadResourceForBlockName($cacheKey, FormView $view, $blockName);
/**
* Loads the cache with the resource for a specific level of a block hierarchy.
*
* @see getResourceForBlockHierarchy()
*
- * @param string $cacheKey The cache key used for storing the
- * resource.
- * @param FormView $view The form view for finding the applying
- * themes.
- * @param array $blockHierarchy The block hierarchy, with the most
- * specific block name at the end.
- * @param integer $hierarchyLevel The level in the block hierarchy that
- * should be loaded.
+ * @param string $cacheKey The cache key used for storing the
+ * resource.
+ * @param FormView $view The form view for finding the applying
+ * themes.
+ * @param array $blockNameHierarchy The block hierarchy, with the most
+ * specific block name at the end.
+ * @param integer $hierarchyLevel The level in the block hierarchy that
+ * should be loaded.
*
* @return Boolean True if the resource could be loaded, false otherwise.
*/
- private function loadResourceForBlockHierarchy($cacheKey, FormView $view, array $blockHierarchy, $hierarchyLevel)
+ private function loadResourceForBlockNameHierarchy($cacheKey, FormView $view, array $blockNameHierarchy, $hierarchyLevel)
{
- $block = $blockHierarchy[$hierarchyLevel];
+ $blockName = $blockNameHierarchy[$hierarchyLevel];
// Try to find a template for that block
- if ($this->loadResourceForBlock($cacheKey, $view, $block)) {
+ if ($this->loadResourceForBlockName($cacheKey, $view, $blockName)) {
// If loadTemplateForBlock() returns true, it was able to populate the
// cache. The only missing thing is to set the hierarchy level at which
// the template was found.
- $this->resourceHierarchyLevels[$cacheKey][$block] = $hierarchyLevel;
+ $this->resourceHierarchyLevels[$cacheKey][$blockName] = $hierarchyLevel;
return true;
}
if ($hierarchyLevel > 0) {
$parentLevel = $hierarchyLevel - 1;
- $parentBlock = $blockHierarchy[$parentLevel];
+ $parentBlockName = $blockNameHierarchy[$parentLevel];
// The next two if statements contain slightly duplicated code. This is by intention
// and tries to avoid execution of unnecessary checks in order to increase performance.
- if (isset($this->resources[$cacheKey][$parentBlock])) {
+ if (isset($this->resources[$cacheKey][$parentBlockName])) {
// It may happen that the parent block is already loaded, but its level is not.
// In this case, the parent block must have been loaded by loadResourceForBlock(),
// which does not check the hierarchy of the block. Subsequently the block must have
// been found directly on the parent level.
- if (!isset($this->resourceHierarchyLevels[$cacheKey][$parentBlock])) {
- $this->resourceHierarchyLevels[$cacheKey][$parentBlock] = $parentLevel;
+ if (!isset($this->resourceHierarchyLevels[$cacheKey][$parentBlockName])) {
+ $this->resourceHierarchyLevels[$cacheKey][$parentBlockName] = $parentLevel;
}
// Cache the shortcuts for further accesses
- $this->resources[$cacheKey][$block] = $this->resources[$cacheKey][$parentBlock];
- $this->resourceHierarchyLevels[$cacheKey][$block] = $this->resourceHierarchyLevels[$cacheKey][$parentBlock];
+ $this->resources[$cacheKey][$blockName] = $this->resources[$cacheKey][$parentBlockName];
+ $this->resourceHierarchyLevels[$cacheKey][$blockName] = $this->resourceHierarchyLevels[$cacheKey][$parentBlockName];
return true;
}
- if ($this->loadResourceForBlockHierarchy($cacheKey, $view, $blockHierarchy, $parentLevel)) {
+ if ($this->loadResourceForBlockNameHierarchy($cacheKey, $view, $blockNameHierarchy, $parentLevel)) {
// Cache the shortcuts for further accesses
- $this->resources[$cacheKey][$block] = $this->resources[$cacheKey][$parentBlock];
- $this->resourceHierarchyLevels[$cacheKey][$block] = $this->resourceHierarchyLevels[$cacheKey][$parentBlock];
+ $this->resources[$cacheKey][$blockName] = $this->resources[$cacheKey][$parentBlockName];
+ $this->resourceHierarchyLevels[$cacheKey][$blockName] = $this->resourceHierarchyLevels[$cacheKey][$parentBlockName];
return true;
}
}
// Cache the result for further accesses
- $this->resources[$cacheKey][$block] = false;
- $this->resourceHierarchyLevels[$cacheKey][$block] = false;
+ $this->resources[$cacheKey][$blockName] = false;
+ $this->resourceHierarchyLevels[$cacheKey][$blockName] = false;
return false;
}
View
2 CHANGELOG.md
@@ -175,5 +175,5 @@ CHANGELOG
* `toArrayKeys`
* `isChoiceGroup`
* `isChoiceSelected`
- * added method `block` to FormHelper and deprecated `renderBlock` instead
+ * [BC BREAK] renamed method `renderBlock` in FormHelper to `block` and changed its signature
* made FormView properties public and deprecated their accessor methods
View
36 Extension/Templating/TemplatingRendererEngine.php
@@ -35,7 +35,7 @@ public function __construct(EngineInterface $engine, array $defaultThemes = arra
/**
* {@inheritdoc}
*/
- public function renderBlock(FormView $view, $resource, $block, array $variables = array())
+ public function renderBlock(FormView $view, $resource, $blockName, array $variables = array())
{
return trim($this->engine->render($resource, $variables));
}
@@ -48,13 +48,13 @@ public function renderBlock(FormView $view, $resource, $block, array $variables
*
* @see getResourceForBlock()
*
- * @param string $cacheKey The cache key of the form view.
- * @param FormView $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, FormView $view, $block)
+ protected function loadResourceForBlockName($cacheKey, FormView $view, $blockName)
{
// Recursively try to find the block in the themes assigned to $view,
// then of its parent form, then of the parent form of the parent and so on.
@@ -64,7 +64,7 @@ protected function loadResourceForBlock($cacheKey, FormView $view, $block)
// Check each theme whether it contains the searched block
if (isset($this->themes[$cacheKey])) {
for ($i = count($this->themes[$cacheKey]) - 1; $i >= 0; --$i) {
- if ($this->loadResourceFromTheme($cacheKey, $block, $this->themes[$cacheKey][$i])) {
+ if ($this->loadResourceFromTheme($cacheKey, $blockName, $this->themes[$cacheKey][$i])) {
return true;
}
}
@@ -73,7 +73,7 @@ protected function loadResourceForBlock($cacheKey, FormView $view, $block)
// 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, $block, $this->defaultThemes[$i])) {
+ if ($this->loadResourceFromTheme($cacheKey, $blockName, $this->defaultThemes[$i])) {
return true;
}
}
@@ -84,38 +84,38 @@ protected function loadResourceForBlock($cacheKey, FormView $view, $block)
if ($view->parent) {
$parentCacheKey = $view->parent->vars[self::CACHE_KEY_VAR];
- if (!isset($this->resources[$parentCacheKey][$block])) {
- $this->loadResourceForBlock($parentCacheKey, $view->parent, $block);
+ if (!isset($this->resources[$parentCacheKey][$blockName])) {
+ $this->loadResourceForBlockName($parentCacheKey, $view->parent, $blockName);
}
// If a template exists in the parent themes, cache that template
// for the current theme as well to speed up further accesses
- if ($this->resources[$parentCacheKey][$block]) {
- $this->resources[$cacheKey][$block] = $this->resources[$parentCacheKey][$block];
+ if ($this->resources[$parentCacheKey][$blockName]) {
+ $this->resources[$cacheKey][$blockName] = $this->resources[$parentCacheKey][$blockName];
return true;
}
}
// Cache that we didn't find anything to speed up further accesses
- $this->resources[$cacheKey][$block] = false;
+ $this->resources[$cacheKey][$blockName] = false;
return false;
}
/**
* Tries to load the resource for a block from a theme.
*
- * @param string $cacheKey The cache key for storing the resource.
- * @param string $block The name of the block to load a resource for.
- * @param mixed $theme The theme to load the block from.
+ * @param string $cacheKey The cache key for storing the resource.
+ * @param string $blockName The name of the block to load a resource for.
+ * @param mixed $theme The theme to load the block from.
*
* @return Boolean True if the resource could be loaded, false otherwise.
*/
- protected function loadResourceFromTheme($cacheKey, $block, $theme)
+ protected function loadResourceFromTheme($cacheKey, $blockName, $theme)
{
- if ($this->engine->exists($templateName = $theme . ':' . $block . '.html.php')) {
- $this->resources[$cacheKey][$block] = $templateName;
+ if ($this->engine->exists($templateName = $theme . ':' . $blockName . '.html.php')) {
+ $this->resources[$cacheKey][$blockName] = $templateName;
return true;
}
View
136 FormRenderer.php
@@ -35,7 +35,7 @@ class FormRenderer implements FormRendererInterface
/**
* @var array
*/
- private $blockHierarchyMap = array();
+ private $blockNameHierarchyMap = array();
/**
* @var array
@@ -50,7 +50,7 @@ class FormRenderer implements FormRendererInterface
/**
* @var array
*/
- private $stack = array();
+ private $variableStack = array();
public function __construct(FormRendererEngineInterface $engine, CsrfProviderInterface $csrfProvider = null)
{
@@ -77,58 +77,6 @@ public function setTheme(FormView $view, $themes)
/**
* {@inheritdoc}
*/
- public function renderEnctype(FormView $view)
- {
- return $this->renderSection($view, 'enctype');
- }
-
- /**
- * {@inheritdoc}
- */
- public function renderRow(FormView $view, array $variables = array())
- {
- return $this->renderSection($view, 'row', $variables);
- }
-
- /**
- * {@inheritdoc}
- */
- public function renderRest(FormView $view, array $variables = array())
- {
- return $this->renderSection($view, 'rest', $variables);
- }
-
- /**
- * {@inheritdoc}
- */
- public function renderWidget(FormView $view, array $variables = array())
- {
- return $this->renderSection($view, 'widget', $variables);
- }
-
- /**
- * {@inheritdoc}
- */
- public function renderErrors(FormView $view)
- {
- return $this->renderSection($view, 'errors');
- }
-
- /**
- * {@inheritdoc}
- */
- public function renderLabel(FormView $view, $label = null, array $variables = array())
- {
- if ($label !== null) {
- $variables += array('label' => $label);
- }
-
- return $this->renderSection($view, 'label', $variables);
- }
-
- /**
- * {@inheritdoc}
- */
public function renderCsrfToken($intention)
{
if (null === $this->csrfProvider) {
@@ -141,18 +89,18 @@ public function renderCsrfToken($intention)
/**
* {@inheritdoc}
*/
- public function renderBlock($block, array $variables = array())
+ public function renderBlock(FormView $view, $blockName, array $variables = array())
{
- if (0 == count($this->stack)) {
+ if (0 == count($this->variableStack)) {
throw new FormException('This method should only be called while rendering a form element.');
}
- list($view, $scopeVariables) = end($this->stack);
+ $scopeVariables = end($this->variableStack);
- $resource = $this->engine->getResourceForBlock($view, $block);
+ $resource = $this->engine->getResourceForBlockName($view, $blockName);
if (!$resource) {
- throw new FormException(sprintf('No block "%s" found while rendering the form.', $block));
+ throw new FormException(sprintf('No block "%s" found while rendering the form.', $blockName));
}
// Merge the passed with the existing attributes
@@ -169,38 +117,30 @@ public function renderBlock($block, array $variables = array())
// cannot be overwritten
$variables = array_replace($scopeVariables, $variables);
- return $this->engine->renderBlock($view, $resource, $block, $variables);
- }
+ $this->variableStack[] = $variables;
- /**
- * {@inheritdoc}
- */
- public function humanize($text)
- {
- return ucfirst(trim(strtolower(preg_replace('/[_\s]+/', ' ', $text))));
+ // Do the rendering
+ $html = $this->engine->renderBlock($view, $resource, $blockName, $variables);
+
+ // Clear the stack
+ array_pop($this->variableStack);
+
+ return $html;
}
/**
- * Renders the given section of a form view.
- *
- * @param FormView $view The form view.
- * @param string $section The name of the section to render.
- * @param array $variables The variables to pass to the template.
- *
- * @return string The HTML markup.
- *
- * @throws Exception\FormException If no fitting template was found.
+ * {@inheritdoc}
*/
- protected function renderSection(FormView $view, $section, array $variables = array())
+ public function searchAndRenderBlock(FormView $view, $blockNameSuffix, array $variables = array())
{
- $renderOnlyOnce = in_array($section, array('row', 'widget'));
+ $renderOnlyOnce = in_array($blockNameSuffix, array('row', 'widget'));
if ($renderOnlyOnce && $view->isRendered()) {
return '';
}
// The cache key for storing the variables and types
- $mapKey = $uniqueBlockName = $view->vars['full_block_name'] . '_' . $section;
+ $mapKey = $uniqueBlockName = $view->vars['full_block_name'] . '_' . $blockNameSuffix;
// In templates, we have to deal with two kinds of block hierarchies:
//
@@ -229,16 +169,16 @@ protected function renderSection(FormView $view, $section, array $variables = ar
// widget() function again to render the block for the parent type.
//
// The second kind is implemented in the following blocks.
- if (!isset($this->blockHierarchyMap[$mapKey])) {
+ if (!isset($this->blockNameHierarchyMap[$mapKey])) {
// INITIAL CALL
// Calculate the hierarchy of template blocks and start on
// the bottom level of the hierarchy (= "_<id>_<section>" block)
- $blockHierarchy = array();
+ $blockNameHierarchy = array();
foreach ($view->vars['types'] as $type) {
- $blockHierarchy[] = $type . '_' . $section;
+ $blockNameHierarchy[] = $type . '_' . $blockNameSuffix;
}
- $blockHierarchy[] = $uniqueBlockName;
- $hierarchyLevel = count($blockHierarchy) - 1;
+ $blockNameHierarchy[] = $uniqueBlockName;
+ $hierarchyLevel = count($blockNameHierarchy) - 1;
// The default variable scope contains all view variables, merged with
// the variables passed explicitly to the helper
@@ -247,30 +187,30 @@ protected function renderSection(FormView $view, $section, array $variables = ar
// RECURSIVE CALL
// If a block recursively calls renderSection() again, resume rendering
// using the parent type in the hierarchy.
- $blockHierarchy = $this->blockHierarchyMap[$mapKey];
+ $blockNameHierarchy = $this->blockNameHierarchyMap[$mapKey];
$hierarchyLevel = $this->hierarchyLevelMap[$mapKey] - 1;
// Reuse the current scope and merge it with the explicitly passed variables
$scopeVariables = $this->variableMap[$mapKey];
}
// Load the resource where this block can be found
- $resource = $this->engine->getResourceForBlockHierarchy($view, $blockHierarchy, $hierarchyLevel);
+ $resource = $this->engine->getResourceForBlockNameHierarchy($view, $blockNameHierarchy, $hierarchyLevel);
// Update the current hierarchy level to the one at which the resource was
// found. For example, if looking for "choice_widget", but only a resource
// is found for its parent "form_widget", then the level is updated here
// to the parent level.
- $hierarchyLevel = $this->engine->getResourceHierarchyLevel($view, $blockHierarchy, $hierarchyLevel);
+ $hierarchyLevel = $this->engine->getResourceHierarchyLevel($view, $blockNameHierarchy, $hierarchyLevel);
// The actually existing block name in $resource
- $block = $blockHierarchy[$hierarchyLevel];
+ $blockName = $blockNameHierarchy[$hierarchyLevel];
// Escape if no resource exists for this block
if (!$resource) {
throw new FormException(sprintf(
'Unable to render the form as none of the following blocks exist: "%s".',
- implode('", "', array_reverse($blockHierarchy))
+ implode('", "', array_reverse($blockNameHierarchy))
));
}
@@ -295,7 +235,7 @@ protected function renderSection(FormView $view, $section, array $variables = ar
// We need to store these values in maps (associative arrays) because within a
// call to widget() another call to widget() can be made, but for a different view
// object. These nested calls should not override each other.
- $this->blockHierarchyMap[$mapKey] = $blockHierarchy;
+ $this->blockNameHierarchyMap[$mapKey] = $blockNameHierarchy;
$this->hierarchyLevelMap[$mapKey] = $hierarchyLevel;
$this->variableMap[$mapKey] = $variables;
@@ -305,16 +245,16 @@ protected function renderSection(FormView $view, $section, array $variables = ar
//
// A stack is sufficient for this purpose, because renderBlock() always accesses
// the immediate next outer scope, which is always stored at the end of the stack.
- $this->stack[] = array($view, $variables);
+ $this->variableStack[] = $variables;
// Do the rendering
- $html = $this->engine->renderBlock($view, $resource, $block, $variables);
+ $html = $this->engine->renderBlock($view, $resource, $blockName, $variables);
// Clear the stack
- array_pop($this->stack);
+ array_pop($this->variableStack);
// Clear the maps
- unset($this->blockHierarchyMap[$mapKey]);
+ unset($this->blockNameHierarchyMap[$mapKey]);
unset($this->hierarchyLevelMap[$mapKey]);
unset($this->variableMap[$mapKey]);
@@ -324,4 +264,12 @@ protected function renderSection(FormView $view, $section, array $variables = ar
return $html;
}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function humanize($text)
+ {
+ return ucfirst(trim(strtolower(preg_replace('/[_\s]+/', ' ', $text))));
+ }
}
View
74 FormRendererEngineInterface.php
@@ -22,8 +22,8 @@
* 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 mixed $themes The theme(s). The type of these themes
+ * is open to the implementation.
*/
public function setTheme(FormView $view, $themes);
@@ -36,15 +36,15 @@ public function setTheme(FormView $view, $themes);
* The type of the resource is decided by the implementation. The resource
* is later passed to {@link renderBlock()} by the rendering algorithm.
*
- * @param FormView $view The view for determining the used themes.
- * First the themes attached directly to the
- * view with {@link setTheme()} are considered,
- * then the ones of its parent etc.
- * @param string $block The name of the block to render.
+ * @param FormView $view The view for determining the used themes.
+ * First the themes attached directly to the
+ * view with {@link setTheme()} are considered,
+ * then the ones of its parent etc.
+ * @param string $blockName The name of the block to render.
*
* @return mixed The renderer resource or false, if none was found.
*/
- public function getResourceForBlock(FormView $view, $block);
+ public function getResourceForBlockName(FormView $view, $blockName);
/**
* Returns the resource for a block hierarchy.
@@ -70,21 +70,23 @@ public function getResourceForBlock(FormView $view, $block);
* The type of the resource is decided by the implementation. The resource
* is later passed to {@link renderBlock()} by the rendering algorithm.
*
- * @param FormView $view The view for determining the used
- * themes. First the themes attached
- * directly to the view with
- * {@link setTheme()} are considered,
- * then the ones of its parent etc.
- * @param array $blockHierarchy The block name hierarchy, with
- * the root block at the beginning.
- * @param integer $hierarchyLevel The level in the hierarchy at
- * which to start looking. Level 0
- * indicates the root block, i.e.
- * the first element of $blockHierarchy.
+ * @param FormView $view The view for determining the
+ * used themes. First the themes
+ * attached directly to the view
+ * with {@link setTheme()} are
+ * considered, then the ones of
+ * its parent etc.
+ * @param array $blockNameHierarchy The block name hierarchy, with
+ * the root block at the beginning.
+ * @param integer $hierarchyLevel The level in the hierarchy at
+ * which to start looking. Level 0
+ * indicates the root block, i.e.
+ * the first element of
+ * $blockNameHierarchy.
*
* @return mixed The renderer resource or false, if none was found.
*/
- public function getResourceForBlockHierarchy(FormView $view, array $blockHierarchy, $hierarchyLevel);
+ public function getResourceForBlockNameHierarchy(FormView $view, array $blockNameHierarchy, $hierarchyLevel);
/**
* Returns the hierarchy level at which a resource can be found.
@@ -112,21 +114,23 @@ public function getResourceForBlockHierarchy(FormView $view, array $blockHierarc
* The type of the resource is decided by the implementation. The resource
* is later passed to {@link renderBlock()} by the rendering algorithm.
*
- * @param FormView $view The view for determining the used
- * themes. First the themes attached
- * directly to the view with
- * {@link setTheme()} are considered,
- * then the ones of its parent etc.
- * @param array $blockHierarchy The block name hierarchy, with
- * the root block at the beginning.
- * @param integer $hierarchyLevel The level in the hierarchy at
- * which to start looking. Level 0
- * indicates the root block, i.e.
- * the first element of $blockHierarchy.
+ * @param FormView $view The view for determining the
+ * used themes. First the themes
+ * attached directly to the view
+ * with {@link setTheme()} are
+ * considered, then the ones of
+ * its parent etc.
+ * @param array $blockNameHierarchy The block name hierarchy, with
+ * the root block at the beginning.
+ * @param integer $hierarchyLevel The level in the hierarchy at
+ * which to start looking. Level 0
+ * indicates the root block, i.e.
+ * the first element of
+ * $blockNameHierarchy.
*
* @return integer|Boolean The hierarchy level or false, if no resource was found.
*/
- public function getResourceHierarchyLevel(FormView $view, array $blockHierarchy, $hierarchyLevel);
+ public function getResourceHierarchyLevel(FormView $view, array $blockNameHierarchy, $hierarchyLevel);
/**
* Renders a block in the given renderer resource.
@@ -135,12 +139,12 @@ public function getResourceHierarchyLevel(FormView $view, array $blockHierarchy,
* or {@link getResourceForBlockHierarchy()}. The type of the resource is
* decided by the implementation.
*
- * @param FormView $view The view to render.
+ * @param FormView $view The view to render.
* @param mixed $resource The renderer resource.
- * @param string $block The name of the block to render.
+ * @param string $blockName The name of the block to render.
* @param array $variables The variables to pass to the template.
*
* @return string The HTML markup.
*/
- public function renderBlock(FormView $view, $resource, $block, array $variables = array());
+ public function renderBlock(FormView $view, $resource, $blockName, array $variables = array());
}
View
86 FormRendererInterface.php
@@ -37,89 +37,33 @@ public function getEngine();
public function setTheme(FormView $view, $themes);
/**
- * Renders the HTML enctype in the form tag, if necessary.
- *
- * Example usage templates:
- *
- * <form action="..." method="post" <?php echo $renderer->renderEnctype($form) ?>>
- *
- * @param FormView $view The view for which to render the encoding type
- *
- * @return string The HTML markup
- */
- public function renderEnctype(FormView $view);
-
- /**
- * Renders the entire row for a form field.
- *
- * A row typically contains the label, errors and widget of a field.
- *
- * @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 renderRow(FormView $view, array $variables = array());
-
- /**
- * Renders views which have not already been rendered.
- *
- * @param FormView $view The parent view
- * @param array $variables An array of variables
- *
- * @return string The HTML markup
- */
- public function renderRest(FormView $view, array $variables = array());
-
- /**
- * Renders the HTML for a given view.
- *
- * Example usage:
- *
- * <?php echo $renderer->renderWidget($form) ?>
- *
- * You can pass options during the call:
- *
- * <?php echo $renderer->renderWidget($form, array('attr' => array('class' => 'foo'))) ?>
- *
- * <?php echo $renderer->renderWidget($form, array('separator' => '+++++)) ?>
- *
- * @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 renderWidget(FormView $view, array $variables = array());
-
- /**
- * Renders the errors of the given view.
+ * Renders a named block of the form theme.
*
- * @param FormView $view The view to render the errors for
+ * @param FormView $view The view for which to render the block.
+ * @param string $blockName The name of the block.
+ * @param array $variables The variables to pass to the template.
*
* @return string The HTML markup
*/
- public function renderErrors(FormView $view);
+ public function renderBlock(FormView $view, $blockName, array $variables = array());
/**
- * Renders the label of the given view.
+ * Searches and renders a block for a given name suffix.
*
- * @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
+ * The block is searched by combining the block names stored in the
+ * form view with the given suffix. If a block name is found, that
+ * block is rendered.
*
- * @return string The HTML markup
- */
- public function renderLabel(FormView $view, $label = null, array $variables = array());
-
- /**
- * Renders a named block of the form theme.
+ * If this method is called recursively, the block search is continued
+ * where a block was found before.
*
- * @param string $block The name of the block.
- * @param array $variables The variables to pass to the template.
+ * @param FormView $view The view for which to render the block.
+ * @param string $blockNameSuffix The suffix of the block name.
+ * @param array $variables The variables to pass to the template.
*
* @return string The HTML markup
*/
- public function renderBlock($block, array $variables = array());
+ public function searchAndRenderBlock(FormView $view, $blockNameSuffix, array $variables = array());
/**
* Renders a CSRF token.

0 comments on commit 0628f2f

Please sign in to comment.
Something went wrong with that request. Please try again.