Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Form / View / Helper / FormButton.php
blob0170bf9add88a9a28550f3438568199e3ba87da8
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Form\View\Helper;
12 use Zend\Form\ElementInterface;
13 use Zend\Form\Exception;
15 class FormButton extends FormInput
17 /**
18 * Attributes valid for the button tag
20 * @var array
22 protected $validTagAttributes = array(
23 'name' => true,
24 'autofocus' => true,
25 'disabled' => true,
26 'form' => true,
27 'formaction' => true,
28 'formenctype' => true,
29 'formmethod' => true,
30 'formnovalidate' => true,
31 'formtarget' => true,
32 'type' => true,
33 'value' => true,
36 /**
37 * Valid values for the button type
39 * @var array
41 protected $validTypes = array(
42 'button' => true,
43 'reset' => true,
44 'submit' => true,
47 /**
48 * Invoke helper as functor
50 * Proxies to {@link render()}.
52 * @param ElementInterface|null $element
53 * @param null|string $buttonContent
54 * @return string|FormButton
56 public function __invoke(ElementInterface $element = null, $buttonContent = null)
58 if (!$element) {
59 return $this;
62 return $this->render($element, $buttonContent);
65 /**
66 * Render a form <button> element from the provided $element,
67 * using content from $buttonContent or the element's "label" attribute
69 * @param ElementInterface $element
70 * @param null|string $buttonContent
71 * @throws Exception\DomainException
72 * @return string
74 public function render(ElementInterface $element, $buttonContent = null)
76 $openTag = $this->openTag($element);
78 if (null === $buttonContent) {
79 $buttonContent = $element->getLabel();
80 if (null === $buttonContent) {
81 throw new Exception\DomainException(sprintf(
82 '%s expects either button content as the second argument, ' .
83 'or that the element provided has a label value; neither found',
84 __METHOD__
85 ));
88 if (null !== ($translator = $this->getTranslator())) {
89 $buttonContent = $translator->translate(
90 $buttonContent, $this->getTranslatorTextDomain()
95 $escape = $this->getEscapeHtmlHelper();
97 return $openTag . $escape($buttonContent) . $this->closeTag();
101 * Generate an opening button tag
103 * @param null|array|ElementInterface $attributesOrElement
104 * @throws Exception\InvalidArgumentException
105 * @throws Exception\DomainException
106 * @return string
108 public function openTag($attributesOrElement = null)
110 if (null === $attributesOrElement) {
111 return '<button>';
114 if (is_array($attributesOrElement)) {
115 $attributes = $this->createAttributesString($attributesOrElement);
116 return sprintf('<button %s>', $attributes);
119 if (!$attributesOrElement instanceof ElementInterface) {
120 throw new Exception\InvalidArgumentException(sprintf(
121 '%s expects an array or Zend\Form\ElementInterface instance; received "%s"',
122 __METHOD__,
123 (is_object($attributesOrElement) ? get_class($attributesOrElement) : gettype($attributesOrElement))
127 $element = $attributesOrElement;
128 $name = $element->getName();
129 if (empty($name) && $name !== 0) {
130 throw new Exception\DomainException(sprintf(
131 '%s requires that the element has an assigned name; none discovered',
132 __METHOD__
136 $attributes = $element->getAttributes();
137 $attributes['name'] = $name;
138 $attributes['type'] = $this->getType($element);
139 $attributes['value'] = $element->getValue();
141 return sprintf(
142 '<button %s>',
143 $this->createAttributesString($attributes)
148 * Return a closing button tag
150 * @return string
152 public function closeTag()
154 return '</button>';
158 * Determine button type to use
160 * @param ElementInterface $element
161 * @return string
163 protected function getType(ElementInterface $element)
165 $type = $element->getAttribute('type');
166 if (empty($type)) {
167 return 'submit';
170 $type = strtolower($type);
171 if (!isset($this->validTypes[$type])) {
172 return 'submit';
175 return $type;