API Enable custom summaries for blogposts

This commit is contained in:
Damian Mooyman 2015-04-13 17:11:34 +12:00
parent 359c2732a9
commit 6283122c9c
2 changed files with 30 additions and 17 deletions

View File

@ -16,7 +16,8 @@ class BlogPost extends Page {
private static $db = array( private static $db = array(
"PublishDate" => "SS_Datetime", "PublishDate" => "SS_Datetime",
"AuthorNames" => "Varchar(1024)" "AuthorNames" => "Varchar(1024)",
"Summary" => "HTMLText",
); );
private static $has_one = array( private static $has_one = array(
@ -40,7 +41,7 @@ class BlogPost extends Page {
); );
private static $searchable_fields = array( private static $searchable_fields = array(
"Title" "Title",
); );
private static $summary_fields = array( private static $summary_fields = array(
@ -111,6 +112,20 @@ class BlogPost extends Page {
$self =& $this; $self =& $this;
$this->beforeUpdateCMSFields(function($fields) use ($self) { $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 // Add featured image
$fields->insertAfter( $fields->insertAfter(
$uploadField = UploadField::create("FeaturedImage", _t("BlogPost.FeaturedImage", "Featured Image")), $uploadField = UploadField::create("FeaturedImage", _t("BlogPost.FeaturedImage", "Featured Image")),

View File

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