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

Debug toolbar