TYPO3 CMS  TYPO3_6-2
AbstractElement.php
Go to the documentation of this file.
1 <?php
3 
22 abstract class AbstractElement {
23 
27  const ELEMENT_TYPE_FORM = 'FORM';
28 
32  const ELEMENT_TYPE_PLAIN = 'PLAIN';
33 
37  const ELEMENT_TYPE_CONTENT = 'CONTENT';
43  protected $elementId;
44 
48  protected $elementType = self::ELEMENT_TYPE_FORM;
49 
55  protected $name;
56 
63  protected $acceptsParentName = FALSE;
64 
70  protected $attributes;
71 
77  protected $additional;
78 
84  protected $layout;
85 
91  protected $value;
92 
99  protected $data;
100 
106  protected $allowedAdditional = array(
107  'label',
108  'legend'
109  );
110 
116  protected $mandatoryAttributes = array();
117 
121  protected $allowedAttributes = array();
122 
128  protected $localCobj;
129 
133  protected $requestHandler;
134 
138  protected $elementCounter;
139 
143  protected $validateClass;
144 
148  protected $filter;
149 
156  public function __construct() {
157  $this->localCobj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
158  $this->requestHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Request');
159  $this->validateClass = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Utility\\ValidatorUtility');
160  $this->elementCounter = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\ElementCounter');
161  $this->setElementId();
162  $this->createAttributes();
163  $this->createAdditional();
164  $this->createFilter();
165  }
166 
173  public function setElementId() {
174  $this->elementId = $this->elementCounter->getElementId();
175  }
176 
183  public function getElementId() {
184  return $this->elementId;
185  }
186 
192  public function getElementType() {
193  return $this->elementType;
194  }
195 
202  public function setName($name = '') {
203  if (is_string($name) === FALSE) {
204  $name = '';
205  }
206  if ($name !== '') {
207  $this->name = $name;
208  } else {
209  $this->name = 'id-' . $this->getElementId();
210  }
211  }
212 
218  public function getName() {
219  return $this->name;
220  }
221 
227  public function acceptsParentName() {
229  }
230 
238  public function setAttribute($attribute, $value) {
239  if (array_key_exists($attribute, $this->allowedAttributes)) {
240  $this->attributes->addAttribute($attribute, $value);
241  }
242  return $this;
243  }
244 
250  public function getAllowedAttributes() {
252  }
253 
259  public function getMandatoryAttributes() {
261  }
262 
268  public function hasAllowedAttributes() {
269  return empty($this->allowedAttributes) === FALSE;
270  }
271 
277  public function hasAllowedAdditionals() {
278  return empty($this->allowedAdditional) === FALSE;
279  }
280 
286  public function getAllowedAdditionals() {
288  }
289 
295  public function getAttributes() {
296  return $this->attributes->getAttributes();
297  }
298 
305  public function hasAttribute($key) {
306  return $this->attributes->hasAttribute($key);
307  }
308 
315  public function getAttributeValue($key) {
316  return $this->attributes->getValue($key);
317  }
318 
324  public function getAdditional() {
325  return $this->additional->getAdditional();
326  }
327 
334  public function getAdditionalObjectByKey($key) {
335  return $this->additional->getAdditionalObjectByKey($key);
336  }
337 
344  public function getAdditionalValue($key) {
345  return $this->additional->getValue($key);
346  }
347 
353  protected function createAttributes() {
354  $className = 'TYPO3\\CMS\\Form\\Domain\\Model\\Attribute\\AttributesAttribute';
355  $this->attributes = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $this->elementId);
356  }
357 
364  public function setLayout($layout = '') {
365  $this->layout = (string) $layout;
366  }
367 
373  public function getLayout() {
374  return $this->layout;
375  }
376 
383  public function setValue($value = '') {
384  $this->value = (string) $value;
385  }
386 
392  public function getValue() {
393  return $this->value;
394  }
395 
402  public function setData($data = '') {
403  $this->data = (string) $data;
404  }
405 
411  public function setMessagesFromValidation() {
412  if ($this->validateClass->hasMessage($this->getName())) {
413  $messages = $this->validateClass->getMessagesByName($this->getName());
414  $this->setAdditional('mandatory', 'COA', $messages);
415  }
416  }
417 
423  public function setErrorsFromValidation() {
424  if ($this->validateClass->hasErrors($this->getName())) {
425  $errors = $this->validateClass->getErrorsByName($this->getName());
426  $this->setAdditional('error', 'COA', $errors);
427  }
428  }
429 
437  public function setAdditional($additional, $type, $value) {
438  $this->additional->addAdditional($additional, $type, $value);
439  return $this;
440  }
441 
448  public function additionalIsSet($key) {
449  return $this->additional->additionalIsSet($key);
450  }
451 
457  protected function createAdditional() {
458  $className = 'TYPO3\\CMS\\Form\\Domain\\Model\\Additional\\AdditionalAdditionalElement';
459  $this->additional = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className);
460  }
461 
469  public function setAdditionalLayout($key, $layout) {
470  $this->additional->setLayout($key, $layout);
471  }
472 
478  protected function createFilter() {
479  $this->filter = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Utility\\FilterUtility');
480  }
481 
490  public function makeFilter($class, $arguments = array()) {
491  $filter = $this->filter->makeFilter($class, $arguments);
492  return $filter;
493  }
494 
502  public function addFilter($filter) {
503  $this->filter->addFilter($filter);
504  }
505 
513  return $this;
514  }
515 
516 }