FormRendererEngineInterface.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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, bool $useDefaultThemes = true);
  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. *
  40. * @return mixed the renderer resource or false, if none was found
  41. */
  42. public function getResourceForBlockName(FormView $view, string $blockName);
  43. /**
  44. * Returns the resource for a block hierarchy.
  45. *
  46. * A block hierarchy is an array which starts with the root of the hierarchy
  47. * and continues with the child of that root, the child of that child etc.
  48. * The following is an example for a block hierarchy:
  49. *
  50. * form_widget
  51. * text_widget
  52. * url_widget
  53. *
  54. * In this example, "url_widget" is the most specific block, while the other
  55. * blocks are its ancestors in the hierarchy.
  56. *
  57. * The second parameter $hierarchyLevel determines the level of the hierarchy
  58. * that should be rendered. For example, if $hierarchyLevel is 2 for the
  59. * above hierarchy, the engine will first look for the block "url_widget",
  60. * then, if that does not exist, for the block "text_widget" etc.
  61. *
  62. * The type of the resource is decided by the implementation. The resource
  63. * is later passed to {@link renderBlock()} by the rendering algorithm.
  64. *
  65. * @param FormView $view The view for determining the used themes.
  66. * First the themes attached directly to
  67. * the view with {@link setTheme()} are
  68. * considered, then the ones of its parent etc.
  69. * @param string[] $blockNameHierarchy The block name hierarchy, with the root block
  70. * at the beginning
  71. * @param int $hierarchyLevel The level in the hierarchy at which to start
  72. * looking. Level 0 indicates the root block, i.e.
  73. * the first element of $blockNameHierarchy.
  74. *
  75. * @return mixed The renderer resource or false, if none was found
  76. */
  77. public function getResourceForBlockNameHierarchy(FormView $view, array $blockNameHierarchy, int $hierarchyLevel);
  78. /**
  79. * Returns the hierarchy level at which a resource can be found.
  80. *
  81. * A block hierarchy is an array which starts with the root of the hierarchy
  82. * and continues with the child of that root, the child of that child etc.
  83. * The following is an example for a block hierarchy:
  84. *
  85. * form_widget
  86. * text_widget
  87. * url_widget
  88. *
  89. * The second parameter $hierarchyLevel determines the level of the hierarchy
  90. * that should be rendered.
  91. *
  92. * If we call this method with the hierarchy level 2, the engine will first
  93. * look for a resource for block "url_widget". If such a resource exists,
  94. * the method returns 2. Otherwise it tries to find a resource for block
  95. * "text_widget" (at level 1) and, again, returns 1 if a resource was found.
  96. * The method continues to look for resources until the root level was
  97. * reached and nothing was found. In this case false is returned.
  98. *
  99. * The type of the resource is decided by the implementation. The resource
  100. * is later passed to {@link renderBlock()} by the rendering algorithm.
  101. *
  102. * @param FormView $view The view for determining the used themes.
  103. * First the themes attached directly to
  104. * the view with {@link setTheme()} are
  105. * considered, then the ones of its parent etc.
  106. * @param string[] $blockNameHierarchy The block name hierarchy, with the root block
  107. * at the beginning
  108. * @param int $hierarchyLevel The level in the hierarchy at which to start
  109. * looking. Level 0 indicates the root block, i.e.
  110. * the first element of $blockNameHierarchy.
  111. *
  112. * @return int|bool The hierarchy level or false, if no resource was found
  113. */
  114. public function getResourceHierarchyLevel(FormView $view, array $blockNameHierarchy, int $hierarchyLevel);
  115. /**
  116. * Renders a block in the given renderer resource.
  117. *
  118. * The resource can be obtained by calling {@link getResourceForBlock()}
  119. * or {@link getResourceForBlockHierarchy()}. The type of the resource is
  120. * decided by the implementation.
  121. *
  122. * @param FormView $view The view to render
  123. * @param mixed $resource The renderer resource
  124. * @param array $variables The variables to pass to the template
  125. *
  126. * @return string The HTML markup
  127. */
  128. public function renderBlock(FormView $view, $resource, string $blockName, array $variables = []);
  129. }