openrat-cms

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

EditorComponent.class.php (1778B)


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