sfWidgetFormSchemaDecorator.class.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * sfWidgetFormSchemaDecorator wraps a form schema widget inside a given HTML snippet.
  11. *
  12. * @package symfony
  13. * @subpackage widget
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfWidgetFormSchemaDecorator.class.php 9046 2008-05-19 08:13:51Z FabianLange $
  16. */
  17. class sfWidgetFormSchemaDecorator extends sfWidgetFormSchema
  18. {
  19. protected
  20. $widget = null,
  21. $decorator = '';
  22. /**
  23. * Constructor.
  24. *
  25. * @param sfWidgetFormSchema $widget A sfWidgetFormSchema instance
  26. * @param string $decorator A decorator string
  27. *
  28. * @see sfWidgetFormSchema
  29. */
  30. public function __construct(sfWidgetFormSchema $widget, $decorator)
  31. {
  32. $this->widget = $widget;
  33. $this->decorator = $decorator;
  34. parent::__construct();
  35. }
  36. /**
  37. * Returns the decorated widget.
  38. *
  39. * @param sfWidget The decorated widget
  40. */
  41. public function getWidget()
  42. {
  43. return $this->widget;
  44. }
  45. /**
  46. * @param string $name The element name
  47. * @param string $value The value displayed in this widget
  48. * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes
  49. * @param array $errors An array of errors for the field
  50. *
  51. * @see sfWidget
  52. */
  53. public function render($name, $values = array(), $attributes = array(), $errors = array())
  54. {
  55. return strtr($this->decorator, array('%content%' => $this->widget->render($name, $values, $attributes, $errors)));
  56. }
  57. /**
  58. * @see sfWidgetFormSchema
  59. */
  60. public function addFormFormatter($name, sfWidgetFormSchemaFormatter $formatter)
  61. {
  62. return $this->widget->addFormFormatter($name, $formatter);
  63. }
  64. /**
  65. * @see sfWidgetFormSchema
  66. */
  67. public function getFormFormatters()
  68. {
  69. return $this->widget->getFormFormatters();
  70. }
  71. /**
  72. * @see sfWidgetFormSchema
  73. */
  74. public function setFormFormatterName($name)
  75. {
  76. $this->widget->setFormFormatterName($name);
  77. }
  78. /**
  79. * @see sfWidgetFormSchema
  80. */
  81. public function getFormFormatterName()
  82. {
  83. return $this->widget->getFormFormatterName();
  84. }
  85. /**
  86. * @see sfWidgetFormSchema
  87. */
  88. public function getFormFormatter()
  89. {
  90. return $this->widget->getFormFormatter();
  91. }
  92. /**
  93. * @see sfWidgetFormSchema
  94. */
  95. public function setNameFormat($format)
  96. {
  97. $this->widget->setNameFormat($format);
  98. }
  99. /**
  100. * @see sfWidgetFormSchema
  101. */
  102. public function getNameFormat()
  103. {
  104. return $this->widget->getNameFormat();
  105. }
  106. /**
  107. * @see sfWidgetFormSchema
  108. */
  109. public function setLabels($labels)
  110. {
  111. $this->widget->setLabels($labels);
  112. }
  113. /**
  114. * @see sfWidgetFormSchema
  115. */
  116. public function getLabels()
  117. {
  118. return $this->widget->getLabels();
  119. }
  120. /**
  121. * @see sfWidgetFormSchema
  122. */
  123. public function setLabel($name, $value)
  124. {
  125. $this->widget->setLabel($name, $value);
  126. }
  127. /**
  128. * @see sfWidgetFormSchema
  129. */
  130. public function getLabel($name)
  131. {
  132. return $this->widget->getLabel($name);
  133. }
  134. /**
  135. * @see sfWidgetFormSchema
  136. */
  137. public function setHelps($helps)
  138. {
  139. $this->widget->setHelps($helps);
  140. }
  141. /**
  142. * @see sfWidgetFormSchema
  143. */
  144. public function getHelps()
  145. {
  146. return $this->widget->getHelps();
  147. }
  148. /**
  149. * @see sfWidgetFormSchema
  150. */
  151. public function setHelp($name, $help)
  152. {
  153. $this->widget->setHelp($name, $help);
  154. }
  155. /**
  156. * @see sfWidgetFormSchema
  157. */
  158. public function getHelp($name)
  159. {
  160. return $this->widget->getHelp($name);
  161. }
  162. /**
  163. * @see sfWidgetFormSchema
  164. */
  165. public function needsMultipartForm()
  166. {
  167. return $this->widget->needsMultipartForm();
  168. }
  169. /**
  170. * @see sfWidgetFormSchema
  171. */
  172. public function renderField($name, $value = null, $attributes = array(), $errors = array())
  173. {
  174. return $this->widget->renderField($name, $value, $attributes, $errors);
  175. }
  176. /**
  177. * @see sfWidgetFormSchemaFormatter
  178. */
  179. public function generateLabel($name)
  180. {
  181. return $this->widget->getFormFormatter()->generateLabel($name);
  182. }
  183. /**
  184. * @see sfWidgetFormSchemaFormatter
  185. */
  186. public function generateLabelName($name)
  187. {
  188. return $this->widget->getFormFormatter()->generateLabelName($name);
  189. }
  190. /**
  191. * @see sfWidgetFormSchema
  192. */
  193. public function generateName($name)
  194. {
  195. return $this->widget->generateName($name);
  196. }
  197. /**
  198. * @see sfWidgetFormSchema
  199. */
  200. public function getParent()
  201. {
  202. return $this->widget->getParent();
  203. }
  204. /**
  205. * @see sfWidgetFormSchema
  206. */
  207. public function setParent(sfWidgetFormSchema $parent = null)
  208. {
  209. $this->widget->setParent($parent);
  210. }
  211. /**
  212. * @see sfWidgetFormSchema
  213. */
  214. public function getFields()
  215. {
  216. return $this->widget->getFields();
  217. }
  218. /**
  219. * @see sfWidgetFormSchema
  220. */
  221. public function getPositions()
  222. {
  223. return $this->widget->getPositions();
  224. }
  225. /**
  226. * @see sfWidgetFormSchema
  227. */
  228. public function setPositions($positions)
  229. {
  230. $this->widget->setPositions($positions);
  231. }
  232. /**
  233. * @see sfWidgetFormSchema
  234. */
  235. public function moveField($field, $action, $pivot = null)
  236. {
  237. return $this->widget->moveField($field, $action, $pivot);
  238. }
  239. /**
  240. * @see sfWidgetFormSchema
  241. */
  242. public function offsetExists($name)
  243. {
  244. return isset($this->widget[$name]);
  245. }
  246. /**
  247. * @see sfWidgetFormSchema
  248. */
  249. public function offsetGet($name)
  250. {
  251. return $this->widget[$name];
  252. }
  253. /**
  254. * @see sfWidgetFormSchema
  255. */
  256. public function offsetSet($name, $widget)
  257. {
  258. $this->widget[$name] = $widget;
  259. }
  260. /**
  261. * @see sfWidgetFormSchema
  262. */
  263. public function offsetUnset($name)
  264. {
  265. unset($this->widget[$name]);
  266. }
  267. public function __clone()
  268. {
  269. $this->widget = clone $this->widget;
  270. }
  271. }