Source of file RollupPage.php
Size: 4,063 Bytes - Last Modified: 2021-12-23T10:02:26+00:00
/var/www/docs.ssmods.com/process/src/src/Model/RollupPage.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 | <?php namespace Logicbrush\RollupPage\Model; use Logicbrush\RollupPage\Controllers\RollupPageController; use Page; use SilverStripe\Forms\OptionsetField; use SilverStripe\ORM\ArrayList; class RollupPage extends Page { const DISPLAY_INLINE = 0; const DISPLAY_LIST = 1; const DISPLAY_TABS = 2; const ROLLUP_PAGE_DISPLAY_TYPE = [ self::DISPLAY_INLINE => 'content', self::DISPLAY_LIST => 'list', self::DISPLAY_TABS => 'tabs', ]; private static $icon = 'logicbrush/silverstripe-rolluppage:images/treeicons/rollup-page.png'; private static $description = 'A page that rolls up content from its children.'; private static $table_name = 'RollupPage'; private static $db = [ 'ShowLinksOnly' => 'Int', ]; /** * Set this to true to disable automatic inclusion of CSS files * @config * @var bool */ private static $block_default_rollup_page_css = false; /** * Set this to true to disable automatic inclusion of Javascript files * @config * @var bool */ private static $block_default_rollup_page_js = false; public function getCMSFields() { $fields = parent::getCMSFields(); $fields->insertBefore( OptionsetField::create( 'ShowLinksOnly', 'Rollup Display', [ 0 => 'Show children inline', 2 => 'Show children in tabs', 1 => 'Show children as links', ] ), 'Content' ); $contentField = $fields->dataFieldByName( 'Content' ); $contentField->setTitle( 'Introduction' ); return $fields; } public function Children() { if ( $this->ShowLinksOnly !== 1 ) { return ArrayList::create(); } $children = parent::Children(); return parent::Children()->exclude( ['Content' => ''] ); } public function getRollupPageDisplayType() { return self::ROLLUP_PAGE_DISPLAY_TYPE[$this->ShowLinksOnly]; } public function Content() { // original content. $content = $this->Content; if ( $this->ShowLinksOnly === self::DISPLAY_LIST || $this->ShowLinksOnly === self::DISPLAY_TABS ) { $content .= '<nav class="rollup-page-navigation-' . $this->getRollupPageDisplayType() . '"><ul>'; foreach ( $this->AllChildren() as $index => $child ) { if ( ! $child->NeverRollup ) { $childContent = $child->hasMethod( 'Content' ) ? $child->Content() : $child->Content; if ( $child->ShowInMenus ) { $content .= '<li' . ( $index === 0 ? ' class="active"' : '' ) . '>'; if ( $childContent ) { $content .= '<a href="' . $child->Link() . '" data-url-segment="' . $child->URLSegment . '">' . $child->MenuTitle . '</a>'; } else { $content .= '<span>' . $child->MenuTitle . '</span>'; } $content .= '</li>'; } } } $content .= '</ul></nav>'; } if ( $this->ShowLinksOnly === self::DISPLAY_INLINE || $this->ShowLinksOnly === self::DISPLAY_TABS ) { foreach ( $this->AllChildren() as $index => $child ) { if ( ! $child->NeverRollup ) { $childContent = $child->hasMethod( 'Content' ) ? $child->Content() : $child->Content; if ( $childContent ) { if ($this->ShowLinksOnly > 0) { $content .= '<div class="rollup-page-content' . ( $index === 0 ? ' active' : '' ) . '" id="rollup-page-content-' . $child->URLSegment . '">'; } // The class may implement a 'BeforeRollup' // method that allows some content to be // inserted before the main content. if ( $child->hasMethod( 'BeforeRollup' ) ) { $content .= $child->BeforeRollup(); } if ($this->ShowLinksOnly != self::DISPLAY_TABS) { // For tabs, the display of the header is redundant. $content .= '<h2><a name="' . $child->URLSegment . '"></a>' . $child->Title . '</h2>'; } $content .= $childContent; // Likewise, there is an 'AfterRollup' method. if ( $child->hasMethod( 'AfterRollup' ) ) { $content .= $child->AfterRollup(); } if ($this->ShowLinksOnly > 0) { $content .= '</div>'; } } } } } return $content; } public function getControllerName() { return RollupPageController::class; } } |