TYPO3 CMS  TYPO3_6-2
CheckboxElement.php
Go to the documentation of this file.
1 <?php
3 
22 
28  protected $allowedAttributes = array(
29  'accesskey' => '',
30  'alt' => '',
31  'checked' => '',
32  'class' => '',
33  'dir' => '',
34  'disabled' => '',
35  'id' => '',
36  'lang' => '',
37  'name' => '',
38  'style' => '',
39  'tabindex' => '',
40  'title' => '',
41  'type' => 'checkbox',
42  'value' => ''
43  );
44 
50  protected $mandatoryAttributes = array(
51  'name',
52  'id'
53  );
54 
61  protected $acceptsParentName = TRUE;
62 
73  if ($this->value === '') {
74  $this->value = (string) $this->getElementId();
75  $this->setAttribute('value', $this->value);
76  }
77  if ($this->requestHandler->has($this->getName())) {
78  $submittedValue = $this->requestHandler->getByMethod($this->getName());
79  if (is_array($submittedValue) && in_array($this->value, $submittedValue)) {
80  $this->setAttribute('checked', 'checked');
81  } elseif ($submittedValue === $this->value) {
82  $this->setAttribute('checked', 'checked');
83  } elseif (is_array($submittedValue) && in_array('on', $submittedValue)) {
84  $this->setAttribute('checked', 'checked');
85  }
86  } elseif ($this->requestHandler->hasRequest()) {
87  $this->attributes->removeAttribute('checked');
88  }
89  return $this;
90  }
91 
99  public function setAttribute($attribute, $value) {
100  if (array_key_exists($attribute, $this->allowedAttributes)) {
101  $this->attributes->addAttribute($attribute, $value);
102  }
103  if ($attribute === 'name') {
105  $nameAttribute = $this->attributes->getAttributeObjectByKey('name');
106  $nameAttribute->setAddition('[]');
107  }
108  return $this;
109  }
110 
111 }