2018-04-21 06:29:32 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// vendor/silverstripe/errorpage/src/ErrorPage.php
|
|
|
|
// extends global Page class
|
2021-03-14 21:45:35 +01:00
|
|
|
//namespace App\Pages;
|
2018-04-21 06:29:32 +02:00
|
|
|
|
2018-08-13 14:13:55 +02:00
|
|
|
use DNADesign\Elemental\Models\ElementContent;
|
2022-01-13 10:54:33 +01:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2020-05-27 04:15:52 +02:00
|
|
|
use SilverStripe\FontAwesome\FontAwesomeField;
|
2021-01-13 20:03:21 +01:00
|
|
|
use TractorCow\Fluent\Extension\FluentSiteTreeExtension;
|
2018-04-21 06:29:32 +02:00
|
|
|
|
|
|
|
class Page extends SiteTree
|
|
|
|
{
|
2020-02-07 20:51:42 +01:00
|
|
|
protected $_cached = [];
|
2022-01-13 10:54:33 +01:00
|
|
|
private static $default_container_class = 'container';
|
2020-05-27 04:15:52 +02:00
|
|
|
private static $db = [
|
|
|
|
'BlockIcon' => 'Varchar(255)',
|
|
|
|
];
|
2019-08-19 10:37:24 +02:00
|
|
|
|
2021-01-13 20:03:21 +01:00
|
|
|
private static $field_include = [
|
|
|
|
'ElementalAreaID',
|
|
|
|
];
|
|
|
|
|
2019-08-19 10:37:24 +02:00
|
|
|
public static function DefaultContainer()
|
|
|
|
{
|
|
|
|
return self::config()->get('default_container_class');
|
|
|
|
}
|
|
|
|
|
2020-05-27 04:15:52 +02:00
|
|
|
public function getSettingsFields()
|
|
|
|
{
|
|
|
|
$fields = parent::getSettingsFields();
|
|
|
|
|
|
|
|
$fields->addFieldsToTab('Root.Icon', [
|
|
|
|
FontAwesomeField::create('BlockIcon', 'Page link Icon'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
2018-08-13 14:13:55 +02:00
|
|
|
/*
|
|
|
|
* Shows custom summary of the post, otherwise
|
|
|
|
* Displays summary of the first content element
|
|
|
|
*/
|
|
|
|
public function Summary($wordsToDisplay = 30)
|
|
|
|
{
|
2022-01-13 10:54:33 +01:00
|
|
|
if (isset($this->_cached['summary' . $wordsToDisplay])) {
|
|
|
|
return $this->_cached['summary' . $wordsToDisplay];
|
2020-02-07 20:51:42 +01:00
|
|
|
}
|
|
|
|
|
2018-08-13 14:13:55 +02:00
|
|
|
$summary = $this->getField('Summary');
|
|
|
|
if ($summary) {
|
2022-01-13 10:54:33 +01:00
|
|
|
$this->_cached['summary' . $wordsToDisplay] = $summary;
|
|
|
|
|
|
|
|
return $this->_cached['summary' . $wordsToDisplay];
|
2018-08-13 14:13:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$element = ElementContent::get()->filter([
|
|
|
|
'ParentID' => $this->ElementalArea()->ID,
|
|
|
|
'HTML:not' => [null],
|
|
|
|
])->first();
|
|
|
|
|
|
|
|
if ($element) {
|
2022-01-13 10:54:33 +01:00
|
|
|
$this->_cached['summary' . $wordsToDisplay] = $element->dbObject('HTML')->Summary($wordsToDisplay);
|
|
|
|
|
|
|
|
return $this->_cached['summary' . $wordsToDisplay];
|
2018-08-13 14:13:55 +02:00
|
|
|
}
|
|
|
|
|
2020-04-20 12:01:08 +02:00
|
|
|
$content = $this->getField('Content');
|
|
|
|
if ($content) {
|
2022-01-13 10:54:33 +01:00
|
|
|
$this->_cached['summary' . $wordsToDisplay] = $this->dbObject('Content')->Summary($wordsToDisplay);
|
|
|
|
|
|
|
|
return $this->_cached['summary' . $wordsToDisplay];
|
2020-04-20 12:01:08 +02:00
|
|
|
}
|
|
|
|
|
2022-01-13 10:54:33 +01:00
|
|
|
$this->_cached['summary' . $wordsToDisplay] = false;
|
|
|
|
|
|
|
|
return $this->_cached['summary' . $wordsToDisplay];
|
2018-08-13 14:13:55 +02:00
|
|
|
}
|
2019-09-07 03:39:49 +02:00
|
|
|
|
|
|
|
public function CSSClass()
|
|
|
|
{
|
|
|
|
return str_replace(['\\'], '-', $this->getField('ClassName'));
|
|
|
|
}
|
2021-01-13 20:03:21 +01:00
|
|
|
|
|
|
|
protected function onBeforeWrite()
|
|
|
|
{
|
|
|
|
parent::onBeforeWrite();
|
|
|
|
|
2022-01-13 10:54:33 +01:00
|
|
|
if (class_exists(FluentSiteTreeExtension::class) && ! $this->isDraftedInLocale() && $this->isInDB()) {
|
2021-01-13 20:03:21 +01:00
|
|
|
$elementalArea = $this->ElementalArea();
|
|
|
|
|
|
|
|
$elementalAreaNew = $elementalArea->duplicate();
|
|
|
|
$this->setField('ElementalAreaID', $elementalAreaNew->ID);
|
|
|
|
}
|
|
|
|
}
|
2018-04-21 06:29:32 +02:00
|
|
|
}
|