TYPO3 CMS  TYPO3_6-2
AttributesAttribute.php
Go to the documentation of this file.
1 <?php
3 
23 
29  protected $attributes = array();
30 
36  protected $elementId;
37 
43  protected $localCobj;
44 
51  public function __construct($elementId) {
52  $this->elementId = (int)$elementId;
53  $this->localCobj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
54  $this->localizationHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Localization');
55  $this->requestHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Request');
56  }
57 
65  public function addAttribute($class, $value) {
66  $attributeName = strtolower((string) $class);
67  $cleanClassName = str_replace(' ', '', ucwords(preg_replace("/[^a-z]/", ' ', $attributeName)));
68  $className = 'TYPO3\\CMS\\Form\\Domain\\Model\\Attribute\\' . $cleanClassName . 'Attribute';
69  $this->attributes[$attributeName] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $value, $this->elementId);
70  return $this;
71  }
72 
79  public function removeAttribute($class) {
80  unset($this->attributes[$class]);
81  return $this;
82  }
83 
89  public function getAttributes() {
90  return $this->attributes;
91  }
92 
99  public function getAttributeObjectByKey($key) {
100  return $this->attributes[$key];
101  }
102 
110  public function setAttribute($key, $attributeObject) {
111  $this->attributes[$key] = (object) $attributeObject;
112  }
113 
120  public function hasAttribute($key) {
121  return isset($this->attributes[$key]);
122  }
123 
131  public function setValue($key, $value) {
132  $this->getAttributeObjectByKey($key)->setValue($value);
133  }
134 
141  public function getValue($key) {
142  if ($this->hasAttribute($key)) {
143  return $this->getAttributeObjectByKey($key)->getValue();
144  } else {
145  return '';
146  }
147  }
148 
149 }