PageNameAction.class.php (1695B)
1 <?php 2 namespace cms\action\page; 3 use cms\action\Method; 4 use cms\action\object\ObjectInfoAction; 5 use cms\action\object\ObjectNameAction; 6 use cms\action\PageAction; 7 use cms\model\BaseObject; 8 use cms\model\Permission; 9 use cms\model\Project; 10 use language\Messages; 11 12 class PageNameAction extends PageAction implements Method { 13 14 public function getRequiredPermission() { 15 return Permission::ACL_WRITE; 16 } 17 18 19 public function view() { 20 21 $languageId = $this->request->getText('languageid'); 22 23 $name = $this->page->getNameForLanguage($languageId); 24 25 $this->setTemplateVars( $name->getProperties() ); 26 27 $alias = $this->page->getAliasForLanguage( $languageId ); 28 29 $this->setTemplateVar( 'alias_filename', $alias->filename ); 30 $this->setTemplateVar( 'alias_folderid', $alias->parentid ); 31 32 $project = Project::create( $this->page->projectid ); 33 $this->setTemplateVar( 'folders' , $project->getAllFlatFolders() ); 34 } 35 36 37 public function post() { 38 39 $parentAction = new ObjectNameAction(); 40 $parentAction->request = $this->request; 41 $parentAction->init(); 42 $parentAction->post(); // Save name and description 43 44 $alias = $this->page->getAliasForLanguage( $this->request->getLanguageId() ); 45 46 $alias->filename = BaseObject::urlify( $this->request->getText( 'alias_filename') ); 47 $alias->parentid = $this->request->getNumber('alias_folderid'); 48 49 // If no alias, remove the alias 50 if ( ! $alias->filename ) { 51 52 $alias->delete(); 53 $this->addNoticeFor( $alias,Messages::DELETED); 54 } 55 else 56 { 57 $alias->persist(); 58 $this->addNoticeFor( $alias,Messages::SAVED); 59 } 60 61 } 62 }