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.

Blog Module /

Discuss the Blog Module.

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

Extending BlogModule


Reply


3 Posts   916 Views

Avatar
Mackodlak

Community Member, 95 Posts

7 June 2011 at 6:55pm

Edited: 07/06/2011 8:00pm

Hello, I'm trying to extend BlogModule, but it doesn't work.
What I've done thus far:

BlogEntryDecorator:

<?php
class BlogEntryDecorator extends SiteTreeDecorator {
function extraStatics() {
   return array(
    'static $db' => array(
      "Source" => "Text",
      "SourceURL" => "Text"
    ),
   
'has_one' => array(
'Photo' => 'Image'      
)
);
}

function updateCMSFields(& $fields){
    $fields->addFieldToTab("Root.Content.Main", new TextField("Source"));
    $fields->addFieldToTab("Root.Content.Main", new TextField("SourceURL));
$fields->addFieldToTab("Root.Content.Image", new SimpleImageField('Photo','An image for this Blog Entry'));
}
}

added DataObject::add_extension('BlogEntry', 'BlogEntryDecorator'); to _config.php

BlogSummary.ss:

<div class="blogSummary">
...
...
   <% if BlogEntryImage %>
      <% control BlogEntryImage %>$CroppedImage(79,89) <% end_control %>
   <% end_if %>
   $Photo
   $ParagraphSummary
   <a href="$SourceURL">$Source</a>
...
...
</div>

When creating new form I get SimpleImageField for entering photo and 2 fields to enter source and sourceurl.
When going to /admin I see the image properly uploaded, but source and sourceurl fields are empty
Nothing shows on site
Please Help!

Avatar
Mackodlak

Community Member, 95 Posts

7 June 2011 at 9:25pm

Edited: 07/06/2011 9:33pm

OK, so I solved most of my problems, Source and SourceURL are imported properly and are usable. Photo is also viewable, but only on the actual blog entry page. For some reason blog summary doesn't show Photo an Source in <p>Izvor: <a href="$SourceURL">$Source</a></p>.

The problem was:

<?php
class BlogEntryDecorator extends SiteTreeDecorator {
function extraStatics() {
return array(
'db' => array( <===== needs to be 'db' instead 'static $db'
"Source" => "Text",
"SourceURL" => "Text"
),

'has_one' => array(
'Photo' => 'Image'
)
);
}

function updateCMSFields(& $fields){
$fields->addFieldToTab("Root.Content.Main", new TextField("Source"));
$fields->addFieldToTab("Root.Content.Main", new TextField("SourceURL));
$fields->addFieldToTab("Root.Content.Image", new SimpleImageField('Photo','An image for this Blog Entry'));
}
}

Avatar
Mackodlak

Community Member, 95 Posts

9 June 2011 at 7:58pm

Edited: 09/06/2011 8:01pm

OK, I have solved all of the problems.
For some reason there was a bug:
The template NewsHolder.ss (NewsHolder.php extends BlogHolder and .ss templates are basically the same) was including the wrong BlogSummary.ss (the one in /blog/templates/includes instead the one in /templates/blackcandy_blog/templates/includes folder; after renaming it to BlogSummary1.ss and including that one it didn't include anything, then I created new file, named it BlogSummary2.ss, copy-pasted all from BlogSummary1.ss to new BlogSummary2.ss and included that one all of it worked - be4 I did it I checked the permissions BlogSummary1.ss had and all seemed fine, I just can't figure it out why it hasn't worked, but it is working now)

Topic can be closed, ty!