[CLEANUP] Improve the @param/@return/@var PHPDoc
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / Domain / Model / Form.php
1 <?php
2 namespace TYPO3\CMS\Form\Domain\Model;
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 * A form
19 *
20 * Takes the incoming Typoscipt and adds all the necessary form objects
21 * according to the configuration.
22 *
23 * @author Patrick Broens <patrick@patrickbroens.nl>
24 */
25 class Form extends \TYPO3\CMS\Form\Domain\Model\Element\ContainerElement {
26
27 /**
28 * Allowed attributes for this object
29 *
30 * @var array
31 */
32 protected $allowedAttributes = array(
33 'accept' => '',
34 'accept-charset' => '',
35 'action' => '',
36 'class' => '',
37 'dir' => '',
38 'enctype' => 'multipart/form-data',
39 'id' => '',
40 'lang' => '',
41 'method' => 'post',
42 'name' => '',
43 'style' => '',
44 'title' => ''
45 );
46
47 /**
48 * Mandatory attributes for this object
49 *
50 * @var array
51 */
52 protected $mandatoryAttributes = array(
53 'method',
54 'action'
55 );
56
57 /**
58 * Set a specific attribute by name and value
59 *
60 * @param string $attribute Name of the attribute
61 * @param mixed $value Value of the attribute
62 * @return Form fluent interface
63 */
64 public function setAttribute($attribute, $value) {
65 if (array_key_exists($attribute, $this->allowedAttributes)) {
66 $this->attributes->addAttribute($attribute, $value);
67 }
68 if ($attribute == 'id' || $attribute == 'name') {
69 $this->equalizeNameAndIdAttribute();
70 }
71 return $this;
72 }
73
74 /**
75 * Makes the value of attributes 'name' and 'id' equal
76 * when both have been filled.
77 *
78 * @return void
79 */
80 protected function equalizeNameAndIdAttribute() {
81 /** @var $nameAttribute \TYPO3\CMS\Form\Domain\Model\Attribute\NameAttribute */
82 $nameAttribute = $this->attributes->getAttributeObjectByKey('name');
83 $idAttribute = $this->attributes->getAttributeObjectByKey('id');
84 if (is_object($nameAttribute) && is_object($idAttribute)) {
85 $nameAttribute->setReturnValueWithoutPrefix(TRUE);
86 $this->attributes->setAttribute('name', $nameAttribute);
87 $nameAttributeValue = $nameAttribute->getValueWithoutPrefix();
88 $idAttributeValue = $idAttribute->getValue('id');
89 if (!empty($nameAttributeValue) && !empty($idAttributeValue)) {
90 $this->attributes->setValue('id', $nameAttributeValue);
91 }
92 }
93 }
94
95 }