Editor.class.php (1485B)
1 <?php 2 3 namespace template_engine\components; 4 5 use template_engine\components\html\FieldComponent; 6 use template_engine\element\CMSElement; 7 use template_engine\element\Value; 8 use template_engine\element\ValueExpression; 9 10 class EditorComponent extends FieldComponent 11 { 12 public $type; 13 public $name; 14 public $mode ='htmlmixed'; 15 public $extension =''; 16 public $mimetype = ''; 17 18 public function createElement() 19 { 20 $textarea = new CMSElement('textarea'); 21 $textarea->addAttribute('name',$this->name); 22 23 $textarea->addStyleClass('input')->addStyleClass('editor')->setEscaping(false); 24 25 switch( $this->type ) 26 { 27 case 'html': 28 $textarea->addStyleClass('html-editor')->addAttribute('id','pageelement_edit_editor'); 29 30 31 break; 32 33 case 'wiki': 34 $textarea->addStyleClass('wiki-editor'); 35 break; 36 37 case 'text': 38 case 'raw': 39 $textarea->addStyleClass('text-editor'); 40 break; 41 42 case 'markdown': 43 $textarea->setEscaping(true)->addStyleClass('markdown-editor'); 44 break; 45 46 case 'code': 47 $textarea->setEscaping(true); 48 $textarea->addStyleClass('code-editor') 49 ->addAttribute('data-extension',$this->extension) 50 ->addAttribute('data-mimetype',$this->mimetype) 51 ->addAttribute('data-mode',$this->mode); 52 break; 53 54 55 default: 56 throw new \LogicException("Unknown editor type: ".$this->type); 57 } 58 59 $textarea->content(Value::createExpression(ValueExpression::TYPE_DATA_VAR,$this->name)); 60 61 return $textarea; 62 } 63 }