sfWidgetFormSchemaDecorator.class.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 12409 2008-10-29 14:06:02Z fabien $
  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 = null)
  124. {
  125. if (2 == func_num_args())
  126. {
  127. $this->widget->setLabel($name, $value);
  128. }
  129. else
  130. {
  131. $this->widget->setLabel($name);
  132. }
  133. }
  134. /**
  135. * @see sfWidgetFormSchema
  136. */
  137. public function getLabel($name = null)
  138. {
  139. return 1 == func_num_args() ? $this->widget->getLabel($name) : $this->widget->getLabel();
  140. }
  141. /**
  142. * @see sfWidgetFormSchema
  143. */
  144. public function setHelps($helps)
  145. {
  146. $this->widget->setHelps($helps);
  147. }
  148. /**
  149. * @see sfWidgetFormSchema
  150. */
  151. public function getHelps()
  152. {
  153. return $this->widget->getHelps();
  154. }
  155. /**
  156. * @see sfWidgetFormSchema
  157. */
  158. public function setHelp($name, $help)
  159. {
  160. $this->widget->setHelp($name, $help);
  161. }
  162. /**
  163. * @see sfWidgetFormSchema
  164. */
  165. public function getHelp($name)
  166. {
  167. return $this->widget->getHelp($name);
  168. }
  169. /**
  170. * Gets the stylesheet paths associated with the widget.
  171. *
  172. * @return array An array of stylesheet paths
  173. */
  174. public function getStylesheets()
  175. {
  176. return $this->widget->getStylesheets();
  177. }
  178. /**
  179. * Gets the JavaScript paths associated with the widget.
  180. *
  181. * @return array An array of JavaScript paths
  182. */
  183. public function getJavaScripts()
  184. {
  185. return $this->widget->getJavaScripts();
  186. }
  187. /**
  188. * @see sfWidgetFormSchema
  189. */
  190. public function needsMultipartForm()
  191. {
  192. return $this->widget->needsMultipartForm();
  193. }
  194. /**
  195. * @see sfWidgetFormSchema
  196. */
  197. public function renderField($name, $value = null, $attributes = array(), $errors = array())
  198. {
  199. return $this->widget->renderField($name, $value, $attributes, $errors);
  200. }
  201. /**
  202. * @see sfWidgetFormSchemaFormatter
  203. */
  204. public function generateLabel($name)
  205. {
  206. return $this->widget->getFormFormatter()->generateLabel($name);
  207. }
  208. /**
  209. * @see sfWidgetFormSchemaFormatter
  210. */
  211. public function generateLabelName($name)
  212. {
  213. return $this->widget->getFormFormatter()->generateLabelName($name);
  214. }
  215. /**
  216. * @see sfWidgetFormSchema
  217. */
  218. public function generateName($name)
  219. {
  220. return $this->widget->generateName($name);
  221. }
  222. /**
  223. * @see sfWidgetFormSchema
  224. */
  225. public function getParent()
  226. {
  227. return $this->widget->getParent();
  228. }
  229. /**
  230. * @see sfWidgetFormSchema
  231. */
  232. public function setParent(sfWidgetFormSchema $parent = null)
  233. {
  234. $this->widget->setParent($parent);
  235. }
  236. /**
  237. * @see sfWidgetFormSchema
  238. */
  239. public function getFields()
  240. {
  241. return $this->widget->getFields();
  242. }
  243. /**
  244. * @see sfWidgetFormSchema
  245. */
  246. public function getPositions()
  247. {
  248. return $this->widget->getPositions();
  249. }
  250. /**
  251. * @see sfWidgetFormSchema
  252. */
  253. public function setPositions($positions)
  254. {
  255. $this->widget->setPositions($positions);
  256. }
  257. /**
  258. * @see sfWidgetFormSchema
  259. */
  260. public function moveField($field, $action, $pivot = null)
  261. {
  262. return $this->widget->moveField($field, $action, $pivot);
  263. }
  264. /**
  265. * @see sfWidgetFormSchema
  266. */
  267. public function offsetExists($name)
  268. {
  269. return isset($this->widget[$name]);
  270. }
  271. /**
  272. * @see sfWidgetFormSchema
  273. */
  274. public function offsetGet($name)
  275. {
  276. return $this->widget[$name];
  277. }
  278. /**
  279. * @see sfWidgetFormSchema
  280. */
  281. public function offsetSet($name, $widget)
  282. {
  283. $this->widget[$name] = $widget;
  284. }
  285. /**
  286. * @see sfWidgetFormSchema
  287. */
  288. public function offsetUnset($name)
  289. {
  290. unset($this->widget[$name]);
  291. }
  292. public function __clone()
  293. {
  294. $this->widget = clone $this->widget;
  295. }
  296. }