silverstripe-webpack/app/src/Pages/Page.php

94 lines
2.7 KiB
PHP
Raw Normal View History

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
use SilverStripe\CMS\Model\SiteTree;
use DNADesign\Elemental\Models\ElementContent;
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
{
private static $default_container_class = 'container';
2020-02-07 20:51:42 +01:00
protected $_cached = [];
2020-05-27 04:15:52 +02:00
private static $db = [
'BlockIcon' => 'Varchar(255)',
];
2021-01-13 20:03:21 +01:00
private static $field_include = [
'ElementalAreaID',
];
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;
}
/*
* Shows custom summary of the post, otherwise
* Displays summary of the first content element
*/
public function Summary($wordsToDisplay = 30)
{
2020-02-07 20:51:42 +01:00
if (isset($this->_cached['summary'.$wordsToDisplay])) {
return $this->_cached['summary'.$wordsToDisplay];
}
$summary = $this->getField('Summary');
if ($summary) {
2020-02-07 20:51:42 +01: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-07 20:51:42 +01:00
$this->_cached['summary'.$wordsToDisplay] = $element->dbObject('HTML')->Summary($wordsToDisplay);
return $this->_cached['summary'.$wordsToDisplay];
}
2020-04-20 12:01:08 +02:00
$content = $this->getField('Content');
if ($content) {
$this->_cached['summary'.$wordsToDisplay] = $this->dbObject('Content')->Summary($wordsToDisplay);
return $this->_cached['summary'.$wordsToDisplay];
}
2020-02-07 20:51:42 +01:00
$this->_cached['summary'.$wordsToDisplay] = false;
return $this->_cached['summary'.$wordsToDisplay];
}
public function CSSClass()
{
return str_replace(['\\'], '-', $this->getField('ClassName'));
}
2021-01-13 20:03:21 +01:00
protected function onBeforeWrite()
{
parent::onBeforeWrite();
if (class_exists(FluentSiteTreeExtension::class) && !$this->isDraftedInLocale() && $this->isInDB()) {
$elementalArea = $this->ElementalArea();
$elementalAreaNew = $elementalArea->duplicate();
$this->setField('ElementalAreaID', $elementalAreaNew->ID);
}
}
2018-04-21 06:29:32 +02:00
}