PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 136 lines | 74 code | 10 blank | 52 comment | 18 complexity | 51664abf6609f3312753458edfe4420b 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_Abstract */
  22. require_once 'Zend/Form/Decorator/Abstract.php';
  23. /**
  24. * Zend_Form_Decorator_FormElements
  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: FormElements.php 24453 2011-09-09 15:14:24Z matthew $
  39. */
  40. class Zend_Form_Decorator_FormElements extends Zend_Form_Decorator_Abstract
  41. {
  42. /**
  43. * Merges given two belongsTo (array notation) strings
  44. *
  45. * @param string $baseBelongsTo
  46. * @param string $belongsTo
  47. * @return string
  48. */
  49. public function mergeBelongsTo($baseBelongsTo, $belongsTo)
  50. {
  51. $endOfArrayName = strpos($belongsTo, '[');
  52. if ($endOfArrayName === false) {
  53. return $baseBelongsTo . '[' . $belongsTo . ']';
  54. }
  55. $arrayName = substr($belongsTo, 0, $endOfArrayName);
  56. return $baseBelongsTo . '[' . $arrayName . ']' . substr($belongsTo, $endOfArrayName);
  57. }
  58. /**
  59. * Render form elements
  60. *
  61. * @param string $content
  62. * @return string
  63. */
  64. public function render($content)
  65. {
  66. $form = $this->getElement();
  67. if ((!$form instanceof Zend_Form) && (!$form instanceof Zend_Form_DisplayGroup)) {
  68. return $content;
  69. }
  70. $belongsTo = ($form instanceof Zend_Form) ? $form->getElementsBelongTo() : null;
  71. $elementContent = '';
  72. $displayGroups = ($form instanceof Zend_Form) ? $form->getDisplayGroups() : array();
  73. $separator = $this->getSeparator();
  74. $translator = $form->getTranslator();
  75. $items = array();
  76. $view = $form->getView();
  77. foreach ($form as $item) {
  78. $item->setView($view)
  79. ->setTranslator($translator);
  80. if ($item instanceof Zend_Form_Element) {
  81. foreach ($displayGroups as $group) {
  82. $elementName = $item->getName();
  83. $element = $group->getElement($elementName);
  84. if ($element) {
  85. // Element belongs to display group; only render in that
  86. // context.
  87. continue 2;
  88. }
  89. }
  90. $item->setBelongsTo($belongsTo);
  91. } elseif (!empty($belongsTo) && ($item instanceof Zend_Form)) {
  92. if ($item->isArray()) {
  93. $name = $this->mergeBelongsTo($belongsTo, $item->getElementsBelongTo());
  94. $item->setElementsBelongTo($name, true);
  95. } else {
  96. $item->setElementsBelongTo($belongsTo, true);
  97. }
  98. } elseif (!empty($belongsTo) && ($item instanceof Zend_Form_DisplayGroup)) {
  99. foreach ($item as $element) {
  100. $element->setBelongsTo($belongsTo);
  101. }
  102. }
  103. $items[] = $item->render();
  104. if (($item instanceof Zend_Form_Element_File)
  105. || (($item instanceof Zend_Form)
  106. && (Zend_Form::ENCTYPE_MULTIPART == $item->getEnctype()))
  107. || (($item instanceof Zend_Form_DisplayGroup)
  108. && (Zend_Form::ENCTYPE_MULTIPART == $item->getAttrib('enctype')))
  109. ) {
  110. if ($form instanceof Zend_Form) {
  111. $form->setEnctype(Zend_Form::ENCTYPE_MULTIPART);
  112. } elseif ($form instanceof Zend_Form_DisplayGroup) {
  113. $form->setAttrib('enctype', Zend_Form::ENCTYPE_MULTIPART);
  114. }
  115. }
  116. }
  117. $elementContent = implode($separator, $items);
  118. switch ($this->getPlacement()) {
  119. case self::PREPEND:
  120. return $elementContent . $separator . $content;
  121. case self::APPEND:
  122. default:
  123. return $content . $separator . $elementContent;
  124. }
  125. }
  126. }