2018-04-21 11:29:32 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// vendor/silverstripe/errorpage/src/ErrorPage.php
|
|
|
|
// extends global Page class
|
2021-03-15 03:45:35 +07:00
|
|
|
//namespace App\Pages;
|
2018-04-21 11:29:32 +07:00
|
|
|
|
2018-08-13 19:13:55 +07:00
|
|
|
use DNADesign\Elemental\Models\ElementContent;
|
2022-01-13 11:54:33 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2023-10-23 18:57:41 +02:00
|
|
|
use SilverStripe\Control\Controller;
|
2020-05-27 09:15:52 +07:00
|
|
|
use SilverStripe\FontAwesome\FontAwesomeField;
|
2023-10-23 18:57:41 +02:00
|
|
|
use SilverStripe\GraphQL\Controller as GraphQLController;
|
2021-01-14 02:03:21 +07:00
|
|
|
use TractorCow\Fluent\Extension\FluentSiteTreeExtension;
|
2018-04-21 11:29:32 +07:00
|
|
|
|
2022-05-10 12:36:40 +02:00
|
|
|
/**
|
|
|
|
* Class \Page
|
|
|
|
*
|
2023-08-04 00:28:22 +02:00
|
|
|
* @property bool $InheritSideBar
|
2022-05-10 12:36:40 +02:00
|
|
|
* @property string $BlockIcon
|
|
|
|
* @property int $SideBarID
|
|
|
|
* @property int $ElementalAreaID
|
|
|
|
* @method \SilverStripe\Widgets\Model\WidgetArea SideBar()
|
|
|
|
* @method \DNADesign\Elemental\Models\ElementalArea ElementalArea()
|
|
|
|
* @mixin \DNADesign\Elemental\Extensions\ElementalPageExtension
|
|
|
|
* @mixin \A2nt\CMSNiceties\Widgets\WidgetPageExtension
|
|
|
|
* @mixin \Sheadawson\Linkable\Extensions\LinkableDataExtension
|
|
|
|
*/
|
2018-04-21 11:29:32 +07:00
|
|
|
class Page extends SiteTree
|
|
|
|
{
|
2020-02-08 02:51:42 +07:00
|
|
|
protected $_cached = [];
|
2022-01-13 11:54:33 +02:00
|
|
|
private static $default_container_class = 'container';
|
2020-05-27 09:15:52 +07:00
|
|
|
private static $db = [
|
|
|
|
'BlockIcon' => 'Varchar(255)',
|
|
|
|
];
|
2019-08-19 15:37:24 +07:00
|
|
|
|
2021-01-14 02:03:21 +07:00
|
|
|
private static $field_include = [
|
|
|
|
'ElementalAreaID',
|
|
|
|
];
|
|
|
|
|
2019-08-19 15:37:24 +07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-08-13 19:13:55 +07:00
|
|
|
/*
|
|
|
|
* Shows custom summary of the post, otherwise
|
|
|
|
* Displays summary of the first content element
|
|
|
|
*/
|
|
|
|
public function Summary($wordsToDisplay = 30)
|
|
|
|
{
|
2022-01-13 11:54:33 +02:00
|
|
|
if (isset($this->_cached['summary' . $wordsToDisplay])) {
|
|
|
|
return $this->_cached['summary' . $wordsToDisplay];
|
2020-02-08 02:51:42 +07:00
|
|
|
}
|
|
|
|
|
2018-08-13 19:13:55 +07:00
|
|
|
$summary = $this->getField('Summary');
|
|
|
|
if ($summary) {
|
2022-01-13 11:54:33 +02:00
|
|
|
$this->_cached['summary' . $wordsToDisplay] = $summary;
|
|
|
|
|
|
|
|
return $this->_cached['summary' . $wordsToDisplay];
|
2018-08-13 19:13:55 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
$element = ElementContent::get()->filter([
|
|
|
|
'ParentID' => $this->ElementalArea()->ID,
|
|
|
|
'HTML:not' => [null],
|
|
|
|
])->first();
|
|
|
|
|
|
|
|
if ($element) {
|
2022-01-13 11:54:33 +02:00
|
|
|
$this->_cached['summary' . $wordsToDisplay] = $element->dbObject('HTML')->Summary($wordsToDisplay);
|
|
|
|
|
|
|
|
return $this->_cached['summary' . $wordsToDisplay];
|
2018-08-13 19:13:55 +07:00
|
|
|
}
|
|
|
|
|
2020-04-20 17:01:08 +07:00
|
|
|
$content = $this->getField('Content');
|
|
|
|
if ($content) {
|
2022-01-13 11:54:33 +02:00
|
|
|
$this->_cached['summary' . $wordsToDisplay] = $this->dbObject('Content')->Summary($wordsToDisplay);
|
|
|
|
|
|
|
|
return $this->_cached['summary' . $wordsToDisplay];
|
2020-04-20 17:01:08 +07:00
|
|
|
}
|
|
|
|
|
2022-01-13 11:54:33 +02:00
|
|
|
$this->_cached['summary' . $wordsToDisplay] = false;
|
|
|
|
|
|
|
|
return $this->_cached['summary' . $wordsToDisplay];
|
2018-08-13 19:13:55 +07:00
|
|
|
}
|
2019-09-07 08:39:49 +07:00
|
|
|
|
|
|
|
public function CSSClass()
|
|
|
|
{
|
|
|
|
return str_replace(['\\'], '-', $this->getField('ClassName'));
|
|
|
|
}
|
2021-01-14 02:03:21 +07:00
|
|
|
|
|
|
|
protected function onBeforeWrite()
|
|
|
|
{
|
|
|
|
parent::onBeforeWrite();
|
|
|
|
|
2022-01-13 11:54:33 +02:00
|
|
|
if (class_exists(FluentSiteTreeExtension::class) && ! $this->isDraftedInLocale() && $this->isInDB()) {
|
2021-01-14 02:03:21 +07:00
|
|
|
$elementalArea = $this->ElementalArea();
|
|
|
|
|
|
|
|
$elementalAreaNew = $elementalArea->duplicate();
|
|
|
|
$this->setField('ElementalAreaID', $elementalAreaNew->ID);
|
|
|
|
}
|
|
|
|
}
|
2018-04-21 11:29:32 +07:00
|
|
|
}
|