PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/src/application/libraries/Zend/Form/Decorator/PrepareElements.php

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 90 lines | 41 code | 6 blank | 43 comment | 7 complexity | 48e8db5dd58b675aab362bc3ed206577 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Form
  17. * @subpackage Decorator
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /** Zend_Form_Decorator_FormElements */
  22. require_once 'Zend/Form/Decorator/FormElements.php';
  23. /**
  24. * Zend_Form_Decorator_PrepareElements
  25. *
  26. * Render all form elements registered with current form
  27. *
  28. * Accepts following options:
  29. * - separator: Separator to use between elements
  30. *
  31. * Any other options passed will be used as HTML attributes of the form tag.
  32. *
  33. * @category Zend
  34. * @package Zend_Form
  35. * @subpackage Decorator
  36. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. * @version $Id: PrepareElements.php 23775 2011-03-01 17:25:24Z ralph $
  39. */
  40. class Zend_Form_Decorator_PrepareElements extends Zend_Form_Decorator_FormElements
  41. {
  42. /**
  43. * Render form elements
  44. *
  45. * @param string $content
  46. * @return string
  47. */
  48. public function render($content)
  49. {
  50. $form = $this->getElement();
  51. if ((!$form instanceof Zend_Form) && (!$form instanceof Zend_Form_DisplayGroup)) {
  52. return $content;
  53. }
  54. $this->_recursivelyPrepareForm($form);
  55. return $content;
  56. }
  57. protected function _recursivelyPrepareForm(Zend_Form $form)
  58. {
  59. $belongsTo = ($form instanceof Zend_Form) ? $form->getElementsBelongTo() : null;
  60. $elementContent = '';
  61. $separator = $this->getSeparator();
  62. $translator = $form->getTranslator();
  63. $view = $form->getView();
  64. foreach ($form as $item) {
  65. $item->setView($view)
  66. ->setTranslator($translator);
  67. if ($item instanceof Zend_Form_Element) {
  68. $item->setBelongsTo($belongsTo);
  69. } elseif (!empty($belongsTo) && ($item instanceof Zend_Form)) {
  70. if ($item->isArray()) {
  71. $name = $this->mergeBelongsTo($belongsTo, $item->getElementsBelongTo());
  72. $item->setElementsBelongTo($name, true);
  73. } else {
  74. $item->setElementsBelongTo($belongsTo, true);
  75. }
  76. $this->_recursivelyPrepareForm($item);
  77. } elseif (!empty($belongsTo) && ($item instanceof Zend_Form_DisplayGroup)) {
  78. foreach ($item as $element) {
  79. $element->setBelongsTo($belongsTo);
  80. }
  81. }
  82. }
  83. }
  84. }