Skip to content

Commit

Permalink
Merge pull request #153 from dhensby/pulls/126
Browse files Browse the repository at this point in the history
Add extension hooks to blog entry form
  • Loading branch information
Damian Mooyman committed Mar 5, 2015
2 parents 09a297d + 3b9c623 commit bffce65
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions code/BlogHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
class BlogHolder extends BlogTree implements PermissionProvider {

private static $icon = "blog/images/blogholder-file.png";

private static $description = "Displays listings of blog entries";

private static $singular_name = 'Blog Holder Page';

private static $plural_name = 'Blog Holder Pages';

private static $db = array(
'AllowCustomAuthors' => 'Boolean',
'ShowFullEntry' => 'Boolean',
'ShowFullEntry' => 'Boolean',
);

private static $has_one = array(
Expand All @@ -35,43 +35,43 @@ class BlogHolder extends BlogTree implements PermissionProvider {
);

function getCMSFields() {
$blogOwners = $this->blogOwners();
$blogOwners = $this->blogOwners();

SiteTree::disableCMSFieldsExtensions();
$fields = parent::getCMSFields();
SiteTree::enableCMSFieldsExtensions();

$fields->addFieldToTab(
'Root.Main',
'Root.Main',
DropdownField::create('OwnerID', 'Blog owner', $blogOwners->map('ID', 'Name')->toArray())
->setEmptyString('(None)')
->setHasEmptyDefault(true),
"Content"
);
$fields->addFieldToTab('Root.Main', new CheckboxField('AllowCustomAuthors', 'Allow non-admins to have a custom author field'), "Content");
$fields->addFieldToTab(
"Root.Main",
"Root.Main",
CheckboxField::create("ShowFullEntry", "Show Full Entry")
->setDescription('Show full content in overviews rather than summary'),
->setDescription('Show full content in overviews rather than summary'),
"Content"
);

$this->extend('updateCMSFields', $fields);

return $fields;
}

/**
* Get members who have BLOGMANAGEMENT and ADMIN permission
*/
*/

function blogOwners($sort = array('FirstName'=>'ASC','Surname'=>'ASC'), $direction = null) {
$members = Permission::get_members_by_permission(array('ADMIN','BLOGMANAGEMENT'));

$members = Permission::get_members_by_permission(array('ADMIN','BLOGMANAGEMENT'));
$members->sort($sort);

$this->extend('extendBlogOwners', $members);

return $members;
}

Expand Down Expand Up @@ -120,10 +120,10 @@ function IsOwner() {
*/
function requireDefaultRecords() {
parent::requireDefaultRecords();

// Skip creation of default records
if(!self::config()->create_default_pages) return;

if(!BlogHolder::get()->exists()) {
$blogholder = new BlogHolder();
$blogholder->Title = "Blog";
Expand Down Expand Up @@ -156,7 +156,7 @@ function requireDefaultRecords() {
$archivewidget->ParentID = $widgetarea->ID;
$archivewidget->write();

$widgetarea->write();
$widgetarea->write();

break; // only apply to one
}
Expand Down Expand Up @@ -196,7 +196,7 @@ class BlogHolder_Controller extends BlogTree_Controller {
'post',
'BlogEntryForm' => 'BLOGMANAGEMENT',
);

function init() {
parent::init();
Requirements::themedCSS("bbcodehelp");
Expand Down Expand Up @@ -225,9 +225,9 @@ function post(){
/**
* A simple form for creating blog entries
*/
function BlogEntryForm() {
function BlogEntryForm() {
if(!Permission::check('BLOGMANAGEMENT')) return Security::permissionFailure();


$id = 0;
if($this->request->latestParam('ID')) {
Expand All @@ -252,7 +252,7 @@ function BlogEntryForm() {
} else {
$tagfield = new TextField('Tags');
}

$field = 'TextField';
if(!$this->AllowCustomAuthors && !Permission::check('ADMIN')) {
$field = 'ReadonlyField';
Expand All @@ -266,7 +266,7 @@ function BlogEntryForm() {
new LiteralField("Tagsnote"," <label id='tagsnote'>"._t('BlogHolder.TE', "For example: sport, personal, science fiction")."<br/>" .
_t('BlogHolder.SPUC', "Please separate tags using commas.")."</label>")
);

$submitAction = new FormAction('postblog', _t('BlogHolder.POST', 'Post blog entry'));

$actions = new FieldList($submitAction);
Expand All @@ -285,6 +285,8 @@ function BlogEntryForm() {
$form->loadDataFrom(array("Author" => Cookie::get("BlogHolder_Name")));
}

$this->extend("updateBlogEntryForm", $form);

return $form;
}

Expand All @@ -311,15 +313,19 @@ function postblog($data, $form) {
$blogentry->Content = str_replace("\r\n", "\n", $form->Fields()->fieldByName('BlogPost')->dataValue());

if(Object::has_extension($this->ClassName, 'Translatable')) {
$blogentry->Locale = $this->Locale;
$blogentry->Locale = $this->Locale;
}

$this->extend("onBeforePostBlog", $blogentry);

$oldMode = Versioned::get_reading_mode();
Versioned::reading_stage('Stage');
$blogentry->write();
$blogentry->publish("Stage", "Live");
Versioned::set_reading_mode($oldMode);

$this->extend("onAfterPostBlog", $blogentry);

$this->redirect($this->Link());
}
}

0 comments on commit bffce65

Please sign in to comment.