File modules/cms/action/template/TemplateSrcelementAction.class.php
Last commit: Fri Feb 26 01:06:01 2021 +0100 Jan Dankert Refactoring accessing the request parameter values.
1 <?php 2 namespace cms\action\template; 3 use cms\action\Method; 4 use cms\action\RequestParams; 5 use cms\action\TemplateAction; 6 use cms\model\Element; 7 use language\Messages; 8 use util\exception\ValidationException; 9 10 11 class TemplateSrcelementAction extends TemplateAction implements Method { 12 public function view() { 13 $elements = array(); 14 $writable_elements = array(); 15 16 foreach( $this->template->getElementIds() as $elid ) 17 { 18 $element = new Element( $elid ); 19 $element->load(); 20 21 $elements[$elid] = $element->name; 22 23 if ( $element->isWritable() ) 24 $writable_elements[$elid] = $element->name; 25 } 26 27 $this->setTemplateVar('elements' ,$elements ); 28 $this->setTemplateVar('writable_elements',$writable_elements); 29 } 30 31 32 33 public function post() { 34 $tplModel = $this->template->loadTemplateModelFor( $this->request->getModelId() ); 35 36 $elementToAdd = new Element( $this->request->getText('elementid') ); 37 $elementToAdd->load(); 38 39 switch( $this->request->getText('type') ) 40 { 41 case 'addelement': 42 $tplModel->src .= "\n".'{{'.$elementToAdd->name.'}}'; 43 break; 44 45 default: 46 throw new ValidationException('type'); 47 } 48 49 $tplModel->persist(); 50 51 $this->addNoticeFor($this->template,Messages::SAVED); 52 } 53 }
Downloadmodules/cms/action/template/TemplateSrcelementAction.class.php
History Fri, 26 Feb 2021 01:06:01 +0100 Jan Dankert Refactoring accessing the request parameter values. Wed, 18 Nov 2020 01:46:36 +0100 Jan Dankert Refactoring of model classes: New method persist() and some other cleanups. Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.