Jump to:

1845 Posts in 1601 Topics by 560 members

Blog Module

SilverStripe Forums » Blog Module » Extending BlogEntry page

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 1098 Views
  • sajok
    Avatar
    Community Member
    82 Posts

    Extending BlogEntry page Link to this post

    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..

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Extending BlogEntry page Link to this post

    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")));

    1098 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.