77 lines
2.2 KiB
PHP
Raw Normal View History

2018-04-21 11:29:32 +07:00
<?php
// vendor/silverstripe/errorpage/src/ErrorPage.php
// extends global Page class
//namespace Site\Pages;
2020-05-27 09:15:52 +07:00
use Sheadawson\Linkable\Forms\LinkField;
2018-04-21 11:29:32 +07:00
use SilverStripe\CMS\Model\SiteTree;
use DNADesign\Elemental\Models\ElementContent;
2020-05-27 09:15:52 +07:00
use SilverStripe\FontAwesome\FontAwesomeField;
2018-04-21 11:29:32 +07:00
class Page extends SiteTree
{
private static $default_container_class = 'container';
2020-02-08 02:51:42 +07:00
protected $_cached = [];
2020-05-27 09:15:52 +07:00
private static $db = [
'BlockIcon' => 'Varchar(255)',
];
public static function DefaultContainer()
{
return self::config()->get('default_container_class');
}
2020-05-27 09:15:52 +07:00
public function getSettingsFields()
{
$fields = parent::getSettingsFields();
$fields->addFieldsToTab('Root.Icon', [
FontAwesomeField::create('BlockIcon', 'Page link Icon'),
]);
return $fields;
}
/*
* Shows custom summary of the post, otherwise
* Displays summary of the first content element
*/
public function Summary($wordsToDisplay = 30)
{
2020-02-08 02:51:42 +07:00
if (isset($this->_cached['summary'.$wordsToDisplay])) {
return $this->_cached['summary'.$wordsToDisplay];
}
$summary = $this->getField('Summary');
if ($summary) {
2020-02-08 02:51:42 +07:00
$this->_cached['summary'.$wordsToDisplay] = $summary;
return $this->_cached['summary'.$wordsToDisplay];
}
$element = ElementContent::get()->filter([
'ParentID' => $this->ElementalArea()->ID,
'HTML:not' => [null],
])->first();
if ($element) {
2020-02-08 02:51:42 +07:00
$this->_cached['summary'.$wordsToDisplay] = $element->dbObject('HTML')->Summary($wordsToDisplay);
return $this->_cached['summary'.$wordsToDisplay];
}
2020-04-20 17:01:08 +07:00
$content = $this->getField('Content');
if ($content) {
$this->_cached['summary'.$wordsToDisplay] = $this->dbObject('Content')->Summary($wordsToDisplay);
return $this->_cached['summary'.$wordsToDisplay];
}
2020-02-08 02:51:42 +07:00
$this->_cached['summary'.$wordsToDisplay] = false;
return $this->_cached['summary'.$wordsToDisplay];
}
public function CSSClass()
{
return str_replace(['\\'], '-', $this->getField('ClassName'));
}
2018-04-21 11:29:32 +07:00
}