mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
API Enable custom summaries for blogposts
This commit is contained in:
parent
359c2732a9
commit
6283122c9c
@ -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")),
|
||||||
@ -308,7 +323,7 @@ class BlogPost extends Page {
|
|||||||
*
|
*
|
||||||
* @param $wordCount int - number of words to display
|
* @param $wordCount int - number of words to display
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
**/
|
**/
|
||||||
public function Excerpt($wordCount = 30) {
|
public function Excerpt($wordCount = 30) {
|
||||||
return $this->dbObject("Content")->LimitWordCount($wordCount);
|
return $this->dbObject("Content")->LimitWordCount($wordCount);
|
||||||
|
@ -11,19 +11,17 @@
|
|||||||
$FeaturedImage.setWidth(795)
|
$FeaturedImage.setWidth(795)
|
||||||
</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>
|
Loading…
Reference in New Issue
Block a user