-
-
Save EHLOVader/3706390 to your computer and use it in GitHub Desktop.
Blog File Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class BlogFiles_Module extends Core_ModuleBase{ | |
/** | |
* Creates the module information object | |
* @return Core_ModuleInfo | |
*/ | |
protected function createModuleInfo(){ | |
return new Core_ModuleInfo( | |
"Blog Files", | |
"Adds files to blog posts", | |
"Pixels & Code."); | |
} | |
public function subscribeEvents(){ | |
Backend::$events->addEvent('blog:onExtendPostForm', $this, 'extend_blogpost_form'); | |
Backend::$events->addEvent('blog:onExtendPostModel', $this, 'extend_blogpost_model'); | |
} | |
public function extend_blogpost_model($blog){ | |
$blog->add_relation('has_many', 'blogfiles', array('class_name'=>'Db_File', 'foreign_key'=>'master_object_id', 'conditions'=>"master_object_class='Blog_Post' and field='blogfiles'", 'order'=>'sort_order, id', 'delete'=>true)); | |
$blog->define_multi_relation_column('blogfiles', 'blogfiles', 'Blog Files', '@name'); | |
} | |
public function extend_blogpost_form($blog, $context=null){ | |
if ($context != 'preview'){ | |
$blog->add_form_field('blogfiles')->renderAs(frm_file_attachments)->renderFilesAs('file_list')->addDocumentLabel('Add file(s)')->tab('Blog Files')->noAttachmentsLabel('There are no files uploaded')->fileDownloadBaseUrl(url('ls_backend/files/get/')); | |
}# else { | |
#$blog->add_form_field('blogfiles', 'right'); | |
#} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment