[TASK] Streamline phpdoc annotations in EXT:fluid
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Form / ButtonViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Form;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Creates a button.
19 *
20 * = Examples =
21 *
22 * <code title="Defaults">
23 * <f:form.button>Send Mail</f:form.button>
24 * </code>
25 * <output>
26 * <button type="submit" name="" value="">Send Mail</button>
27 * </output>
28 *
29 * <code title="Disabled cancel button with some HTML5 attributes">
30 * <f:form.button type="reset" name="buttonName" value="buttonValue" disabled="disabled" formmethod="post" formnovalidate="formnovalidate">Cancel</f:form.button>
31 * </code>
32 * <output>
33 * <button disabled="disabled" formmethod="post" formnovalidate="formnovalidate" type="reset" name="myForm[buttonName]" value="buttonValue">Cancel</button>
34 * </output>
35 */
36 class ButtonViewHelper extends AbstractFormFieldViewHelper
37 {
38 /**
39 * @var string
40 */
41 protected $tagName = 'button';
42
43 /**
44 * Initialize the arguments.
45 *
46 * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
47 */
48 public function initializeArguments()
49 {
50 parent::initializeArguments();
51 $this->registerTagAttribute(
52 'autofocus',
53 'string',
54 'Specifies that a button should automatically get focus when the page loads'
55 );
56 $this->registerTagAttribute(
57 'disabled',
58 'string',
59 'Specifies that the input element should be disabled when the page loads'
60 );
61 $this->registerTagAttribute('form', 'string', 'Specifies one or more forms the button belongs to');
62 $this->registerTagAttribute(
63 'formaction',
64 'string',
65 'Specifies where to send the form-data when a form is submitted. Only for type="submit"'
66 );
67 $this->registerTagAttribute(
68 'formenctype',
69 'string',
70 'Specifies how form-data should be encoded before sending it to a server. Only for type="submit" (e.g. "application/x-www-form-urlencoded", "multipart/form-data" or "text/plain")'
71 );
72 $this->registerTagAttribute(
73 'formmethod',
74 'string',
75 'Specifies how to send the form-data (which HTTP method to use). Only for type="submit" (e.g. "get" or "post")'
76 );
77 $this->registerTagAttribute(
78 'formnovalidate',
79 'string',
80 'Specifies that the form-data should not be validated on submission. Only for type="submit"'
81 );
82 $this->registerTagAttribute(
83 'formtarget',
84 'string',
85 'Specifies where to display the response after submitting the form. Only for type="submit" (e.g. "_blank", "_self", "_parent", "_top", "framename")'
86 );
87 $this->registerUniversalTagAttributes();
88 $this->registerArgument('type', 'string', 'Specifies the type of button (e.g. "button", "reset" or "submit")', false, 'submit');
89 }
90
91 /**
92 * Renders the button.
93 *
94 * @return string
95 */
96 public function render()
97 {
98 $type = $this->arguments['type'];
99 $name = $this->getName();
100 $this->registerFieldNameForFormTokenGeneration($name);
101
102 $this->tag->addAttribute('type', $type);
103 $this->tag->addAttribute('name', $name);
104 $this->tag->addAttribute('value', $this->getValueAttribute());
105 $this->tag->setContent($this->renderChildren());
106
107 return $this->tag->render();
108 }
109 }