Merge pull request #182 from tractorcow/pulls/2.0/custom-summaries

API Enable custom summaries for blogposts
This commit is contained in:
Christopher Pitt 2015-04-13 17:52:33 +12:00
commit c03ec88467
2 changed files with 30 additions and 17 deletions

View File

@ -16,7 +16,8 @@ class BlogPost extends Page {
private static $db = array(
"PublishDate" => "SS_Datetime",
"AuthorNames" => "Varchar(1024)"
"AuthorNames" => "Varchar(1024)",
"Summary" => "HTMLText",
);
private static $has_one = array(
@ -40,7 +41,7 @@ class BlogPost extends Page {
);
private static $searchable_fields = array(
"Title"
"Title",
);
private static $summary_fields = array(
@ -111,6 +112,20 @@ class BlogPost extends Page {
$self =& $this;
$this->beforeUpdateCMSFields(function($fields) use ($self) {
// Add blog summary
$summaryHolder = ToggleCompositeField::create(
'CustomSummary',
_t('BlogPost.CUSTOMSUMMARY', 'Add A Custom Summary'),
array(
$summary = HtmlEditorField::create("Summary")
)
)->setHeadingLevel(4);
$summary->setDescription(_t(
'BlogPost.SUMMARY_DESCRIPTION',
"If no summary is specified the first 30 words will be used."
));
$fields->insertBefore($summaryHolder, 'Content');
// Add featured image
$fields->insertAfter(
$uploadField = UploadField::create("FeaturedImage", _t("BlogPost.FeaturedImage", "Featured Image")),

View File

@ -12,18 +12,16 @@
</a>
</p>
<% if $Excerpt %>
<p>
$Excerpt
<a href="$Link">
<%t Blog.ReadMoreAbout "Read more about '{title}'..." title=$Title %>
</a>
</p>
<% else %>
<p><a href="$Link">
<%t Blog.ReadMoreAbout "Read more about '{title}'..." title=$Title %>
</a></p>
<% end_if %>
<% if $Summary %>
$Summary
<p>
<% else %>
<p>$Excerpt
<% end_if %>
<a href="$Link">
<%t Blog.ReadMoreAbout "Read more about '{title}'..." title=$Title %>
</a>
</p>
<% include EntryMeta %>
</div>