mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Merge pull request #182 from tractorcow/pulls/2.0/custom-summaries
API Enable custom summaries for blogposts
This commit is contained in:
commit
c03ec88467
@ -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);
|
||||
|
@ -11,19 +11,17 @@
|
||||
$FeaturedImage.setWidth(795)
|
||||
</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>
|
Loading…
Reference in New Issue
Block a user