Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Blog Module /

Discuss the Blog Module.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Extending BlogEntry page


Go to End


2 Posts   1705 Views

Avatar
sajok

Community Member, 82 Posts

29 August 2010 at 11:36am

Edited: 29/08/2010 12:10pm

Hello,

I'm currently working on a small news website. So in order to create different news sections, I'm using the Blog module. I set multiple BlogTrees as the main menu items (Politics, Economy, Sports,...), which include multiple BlogHolders. Each Blogholder page has BlogEntries. Now I want to extend the Blog entries to have 3 additional fields in CMS Admin :

DropDownField : categories (report, Interview, Investigation,..) because I want to show the latest Interview in homepage.
Boolean : IsBreaking News
Image : Photo

I followed this doc page http://doc.silverstripe.org/dataobjectdecorator to extend BlogEntry page. So I created the file mysite/code/BlogEntryDecorator.php with the following code in it:

<?php

/*  extends BlogEntry page  */

class BlogEntryDecorator extends DataObjectDecorator {

    function extraStatics() {
            return array(
                    'db' => array(
                            'Category' => "Enum('Reportage,Raport,Entrevue,Investigation','Reportage')",
                            'IsBreaking'=>'Boolean',
                    ),
		    'has_one' => array(
				'Photo' => 'Image',
			),
            );
    }

    public function updateCMSFields(FieldSet $fields) {
        $fields->addFieldToTab('Root.Content.Photo', new ImageField("Image", _t("BlogEntry.IMAGE", "Article Photo")));
        $fields->addFieldToTab('Root.Content.Main', new DropdownField("Category", _t("BlogEntry.CATEGORY", "Category"),$this->owner->dbObject('Category')->enumValues()));
        $fields->addFieldToTab('Root.Content.Main', new CheckboxField($name = "IsBreaking",$title = _t("BlogEntry.BREAKING", "Breaking News")));
    }
}

I also added the following to mysite/_config.php :

Object::add_extension('BlogEntry', 'BlogEntryDecorator');

However, the above code triggers this error for the image only:

[User Error] Uncaught Exception: Object->__call(): the method 'image' does not exist on 'BlogEntry'

So first, is this a correct way to set the structure of such a news site?
if so, what could be the cause of this error?

Thanks in advance..

Avatar
Willr

Forum Moderator, 5523 Posts

29 August 2010 at 2:01pm

You use 'Image' as the form field name, but the name in the Database is Photo. That could be causing trouble

$fields->addFieldToTab('Root.Content.Photo', new ImageField("Photo", _t("BlogEntry.IMAGE", "Article Photo")));