コード例 #1
0
ファイル: TagBuilderTest.php プロジェクト: plan2net/TYPO3.CMS
 /**
  * @test
  */
 public function tagIsNotRenderedIfTagNameIsEmpty()
 {
     $tagBuilder = new \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder('foo');
     $tagBuilder->setTagName('');
     $this->assertEquals('', $tagBuilder->render());
 }
コード例 #2
0
 /**
  * @param string $value
  * @param boolean $multiple
  * @return string
  */
 protected function renderInputTag($value, $multiple)
 {
     $name = $this->getName();
     $checked = FALSE;
     if ($this->isObjectAccessorMode()) {
         $propertyValue = $this->getPropertyValue();
         if ($propertyValue instanceof \Traversable) {
             $propertyValue = iterator_to_array($propertyValue);
         }
         if (is_array($propertyValue)) {
             if ($checked === NULL) {
                 $checked = in_array($value, $propertyValue);
             }
             $multiple = TRUE;
         } elseif ($propertyValue !== NULL) {
             $checked = (bool) $propertyValue === (bool) $value;
         }
     } else {
         if (isset($this->arguments['value'])) {
             $checked = in_array($value, $this->arguments['value']);
         }
     }
     if ($multiple) {
         $name .= '[]';
     }
     $this->registerFieldNameForFormTokenGeneration($name);
     $tag = new \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder('input');
     $tag->addAttributes(array('name' => $name, 'value' => $value, 'type' => 'checkbox'));
     if ($checked) {
         $tag->addAttribute('checked', 'checked');
     }
     return $tag->render();
 }
コード例 #3
0
 /**
  * @param string $value
  * @return string
  */
 protected function renderInputTag($value)
 {
     $checked = FALSE;
     $propertyValue = FALSE;
     if ($this->isObjectAccessorMode()) {
         try {
             $propertyValue = $this->getPropertyValue();
         } catch (\TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException $exception) {
             // https://review.typo3.org/#/c/4413/4/Classes/ViewHelpers/Form/CheckboxViewHelper.php
             // http://forge.typo3.org/issues/5636
         }
         $checked = $propertyValue == $value;
         // not a type-safe comparison by intention
     }
     if ($propertyValue == FALSE && (isset($this->arguments['value']) && $this->arguments['value'] == $value || $this->getValue() == $value)) {
         $checked = TRUE;
     }
     $tag = new \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder('input');
     $tag->addAttributes(array('value' => $value, 'type' => 'radio', 'name' => $this->getName()));
     if ($checked) {
         $tag->addAttribute('checked', 'checked');
     }
     return $tag->render();
 }