Source of file PageHelper.php
Size: 1,687 Bytes - Last Modified: 2022-02-21T10:02:08+00:00
/var/www/docs.ssmods.com/process/src/src/PageHelper.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 | <?php namespace Arillo\Utils; use SilverStripe\View\TemplateGlobalProvider; use SilverStripe\CMS\Controllers\ModelAsController; /** * Helper for Pages & templates functions. * * @package Arillo * @subpackage Utils * @author <bumbus sf@arillo.net> */ class PageHelper implements TemplateGlobalProvider { public static function get_template_global_variables() { return [ 'PageInstance' => [ 'method' => 'page_instance' ], 'PageControllerInstance' => [ 'method' => 'pagecontroller_instance' ], ]; } /** * Find a page instance by classname. * * @param string $pageType * @param boolean $strict strict mode disables inheritance * @return SiteTree|null */ public static function page_instance( string $pageType, bool $strict = true ) { $page = null; $filter = []; if ($strict) $filter['ClassName'] = $pageType; if (class_exists($pageType) && ($page = $pageType::get()->filter($filter)) && $page->exists()) { return $page->first(); } return null; } /** * Get a controller instance by Page classname. * * @param string $pageType * @param boolean $strict strict mode disables inheritance * @return Controller|null */ public static function pagecontroller_instance( string $pageType, bool $strict = true ) { if ($page = self::page_instance($pageType, $strict)) { return ModelAsController::controller_for($page); } return null; } } |