From 6283122c9c462a877a7cf807e091928baf34ef59 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Mon, 13 Apr 2015 17:11:34 +1200 Subject: [PATCH] API Enable custom summaries for blogposts --- code/model/BlogPost.php | 21 ++++++++++++++++++--- templates/Includes/PostSummary.ss | 26 ++++++++++++-------------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/code/model/BlogPost.php b/code/model/BlogPost.php index be67b54..d1ce042 100644 --- a/code/model/BlogPost.php +++ b/code/model/BlogPost.php @@ -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")), @@ -308,7 +323,7 @@ class BlogPost extends Page { * * @param $wordCount int - number of words to display * - * @return string + * @return string **/ public function Excerpt($wordCount = 30) { return $this->dbObject("Content")->LimitWordCount($wordCount); diff --git a/templates/Includes/PostSummary.ss b/templates/Includes/PostSummary.ss index ec40a30..38af838 100644 --- a/templates/Includes/PostSummary.ss +++ b/templates/Includes/PostSummary.ss @@ -11,19 +11,17 @@ $FeaturedImage.setWidth(795)

- - <% if $Excerpt %> -

- $Excerpt - - <%t Blog.ReadMoreAbout "Read more about '{title}'..." title=$Title %> - -

- <% else %> -

- <%t Blog.ReadMoreAbout "Read more about '{title}'..." title=$Title %> -

- <% end_if %> - + + <% if $Summary %> + $Summary +

+ <% else %> +

$Excerpt + <% end_if %> + + <%t Blog.ReadMoreAbout "Read more about '{title}'..." title=$Title %> + +

+ <% include EntryMeta %> \ No newline at end of file