FormRendererEngineInterface.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Form;
  11. /**
  12. * Adapter for rendering form templates with a specific templating engine.
  13. *
  14. * @author Bernhard Schussek <bschussek@gmail.com>
  15. */
  16. interface FormRendererEngineInterface
  17. {
  18. /**
  19. * Sets the theme(s) to be used for rendering a view and its children.
  20. *
  21. * @param FormView $view The view to assign the theme(s) to
  22. * @param mixed $themes The theme(s). The type of these themes
  23. * is open to the implementation.
  24. */
  25. public function setTheme(FormView $view, $themes);
  26. /**
  27. * Returns the resource for a block name.
  28. *
  29. * The resource is first searched in the themes attached to $view, then
  30. * in the themes of its parent view and so on, until a resource was found.
  31. *
  32. * The type of the resource is decided by the implementation. The resource
  33. * is later passed to {@link renderBlock()} by the rendering algorithm.
  34. *
  35. * @param FormView $view The view for determining the used themes.
  36. * First the themes attached directly to the
  37. * view with {@link setTheme()} are considered,
  38. * then the ones of its parent etc.
  39. * @param string $blockName The name of the block to render
  40. *
  41. * @return mixed the renderer resource or false, if none was found
  42. */
  43. public function getResourceForBlockName(FormView $view, $blockName);
  44. /**
  45. * Returns the resource for a block hierarchy.
  46. *
  47. * A block hierarchy is an array which starts with the root of the hierarchy
  48. * and continues with the child of that root, the child of that child etc.
  49. * The following is an example for a block hierarchy:
  50. *
  51. * form_widget
  52. * text_widget
  53. * url_widget
  54. *
  55. * In this example, "url_widget" is the most specific block, while the other
  56. * blocks are its ancestors in the hierarchy.
  57. *
  58. * The second parameter $hierarchyLevel determines the level of the hierarchy
  59. * that should be rendered. For example, if $hierarchyLevel is 2 for the
  60. * above hierarchy, the engine will first look for the block "url_widget",
  61. * then, if that does not exist, for the block "text_widget" etc.
  62. *
  63. * The type of the resource is decided by the implementation. The resource
  64. * is later passed to {@link renderBlock()} by the rendering algorithm.
  65. *
  66. * @param FormView $view The view for determining the used themes.
  67. * First the themes attached directly to
  68. * the view with {@link setTheme()} are
  69. * considered, then the ones of its parent etc.
  70. * @param array $blockNameHierarchy The block name hierarchy, with the root block
  71. * at the beginning
  72. * @param int $hierarchyLevel The level in the hierarchy at which to start
  73. * looking. Level 0 indicates the root block, i.e.
  74. * the first element of $blockNameHierarchy.
  75. *
  76. * @return mixed The renderer resource or false, if none was found
  77. */
  78. public function getResourceForBlockNameHierarchy(FormView $view, array $blockNameHierarchy, $hierarchyLevel);
  79. /**
  80. * Returns the hierarchy level at which a resource can be found.
  81. *
  82. * A block hierarchy is an array which starts with the root of the hierarchy
  83. * and continues with the child of that root, the child of that child etc.
  84. * The following is an example for a block hierarchy:
  85. *
  86. * form_widget
  87. * text_widget
  88. * url_widget
  89. *
  90. * The second parameter $hierarchyLevel determines the level of the hierarchy
  91. * that should be rendered.
  92. *
  93. * If we call this method with the hierarchy level 2, the engine will first
  94. * look for a resource for block "url_widget". If such a resource exists,
  95. * the method returns 2. Otherwise it tries to find a resource for block
  96. * "text_widget" (at level 1) and, again, returns 1 if a resource was found.
  97. * The method continues to look for resources until the root level was
  98. * reached and nothing was found. In this case false is returned.
  99. *
  100. * The type of the resource is decided by the implementation. The resource
  101. * is later passed to {@link renderBlock()} by the rendering algorithm.
  102. *
  103. * @param FormView $view The view for determining the used themes.
  104. * First the themes attached directly to
  105. * the view with {@link setTheme()} are
  106. * considered, then the ones of its parent etc.
  107. * @param array $blockNameHierarchy The block name hierarchy, with the root block
  108. * at the beginning
  109. * @param int $hierarchyLevel The level in the hierarchy at which to start
  110. * looking. Level 0 indicates the root block, i.e.
  111. * the first element of $blockNameHierarchy.
  112. *
  113. * @return int|bool The hierarchy level or false, if no resource was found
  114. */
  115. public function getResourceHierarchyLevel(FormView $view, array $blockNameHierarchy, $hierarchyLevel);
  116. /**
  117. * Renders a block in the given renderer resource.
  118. *
  119. * The resource can be obtained by calling {@link getResourceForBlock()}
  120. * or {@link getResourceForBlockHierarchy()}. The type of the resource is
  121. * decided by the implementation.
  122. *
  123. * @param FormView $view The view to render
  124. * @param mixed $resource The renderer resource
  125. * @param string $blockName The name of the block to render
  126. * @param array $variables The variables to pass to the template
  127. *
  128. * @return string The HTML markup
  129. */
  130. public function renderBlock(FormView $view, $resource, $blockName, array $variables = array());
  131. }