openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

RadioComponent.class.php (1645B)


      1 <?php
      2 
      3 namespace template_engine\components\html\component_radio;
      4 
      5 use template_engine\components\html\FieldComponent;
      6 use template_engine\element\CMSElement;
      7 use template_engine\element\PHPBlockElement;
      8 use template_engine\element\Value;
      9 use template_engine\element\ValueExpression;
     10 
     11 class RadioComponent extends FieldComponent
     12 {
     13 
     14 	// Bisher nicht in Benutzung.
     15 	public $readonly = false;
     16 
     17 	public $value;
     18 
     19 	public $prefix='';
     20 
     21 	public $suffix='';
     22 
     23 	public $class = '';
     24 
     25 	public $onchange;
     26 
     27 	public $children;
     28 
     29 	public $checked;
     30 
     31 	public $label = '';
     32 
     33 
     34 
     35 	public function createElement()
     36 	{
     37 
     38 		$radio = (new CMSElement('input'))
     39 			->addAttribute('type','radio')
     40 			->addStyleClass('form-radio');
     41 
     42 
     43 		$radio->addAttribute('name',$this->name);
     44 		if   ($this->readonly)
     45 			$radio->addAttribute('disabled','disabled');
     46 		$radio->addAttribute('value',$this->value);
     47 
     48 		$condition = '@$'.PHPBlockElement::value($this->name).'==\''.$this->value.'\'';
     49 		$radio->addConditionalAttribute('checked', $condition, 'checked');
     50 
     51 		//$radio->addAttribute('checked',Value::createExpression(ValueExpression::TYPE_DATA_VAR,$this->name));
     52 
     53 		if ( $this->readonly && $this->required ) {
     54 			$hidden = (new CMSElement('input'))->addAttribute('type','hidden')->addAttribute('name',$this->name)->addAttribute('value','1');
     55 			$radio->addChild( $hidden );
     56 		}
     57 
     58 		if   ( $this->class )
     59 			$radio->addStyleClass($this->class);
     60 
     61 		if   ( $this->label ) {
     62 			$label = (new CMSElement('label'))
     63 				->addChild( $radio )
     64 				->addChild( (new CMSElement('span'))
     65 					->addStyleClass('form-label')
     66 					->content($this->label));
     67 			return $label;
     68 		}
     69 
     70 		return $radio;
     71     }
     72 }