mirror of
https://github.com/flextype/flextype.git
synced 2025-08-12 16:14:16 +02:00
Updates for event listener and templates loader
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\{Arr\Arr, Http\Http, Filesystem\Filesystem};
|
||||
use Flextype\Component\{Arr\Arr, Http\Http, Filesystem\Filesystem, Event\Event};
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class Pages
|
||||
@@ -50,7 +50,10 @@ class Pages
|
||||
protected static function init() : void
|
||||
{
|
||||
// The page is not processed and not sent to the display.
|
||||
Events::dispatch('onPageBeforeRender');
|
||||
Event::dispatch('onPageBeforeRender');
|
||||
|
||||
// Add parseContent on content event
|
||||
Event::addListener('content', 'Flextype\Pages::parseContent');
|
||||
|
||||
// Get current page
|
||||
static::$page = static::getPage(Http::getUriString());
|
||||
@@ -59,7 +62,7 @@ class Pages
|
||||
static::renderPage(static::$page);
|
||||
|
||||
// The page has been fully processed and sent to the display.
|
||||
Events::dispatch('onPageAfterRender');
|
||||
Event::dispatch('onPageAfterRender');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +104,7 @@ class Pages
|
||||
*/
|
||||
public static function renderPage(array $page)
|
||||
{
|
||||
View::factory(empty($page['template']) ? 'default' : $page['template'])
|
||||
Themes::template(empty($page['template']) ? 'default' : $page['template'])
|
||||
->assign('page', $page, true)
|
||||
->display();
|
||||
}
|
||||
@@ -157,12 +160,12 @@ class Pages
|
||||
if ($raw) {
|
||||
$page = trim(Filesystem::getFileContent($file));
|
||||
static::$page = $page;
|
||||
Events::dispatch('onPageContentRawAfter');
|
||||
Event::dispatch('onPageContentRawAfter');
|
||||
} else {
|
||||
$page = static::parseFile($file);
|
||||
static::$page = $page;
|
||||
static::$page['content'] = Filters::dispatch('content', static::parseContent(static::$page['content']));
|
||||
Events::dispatch('onPageContentAfter');
|
||||
static::$page['content'] = Event::dispatch('content', ['content' => static::$page['content']], true);
|
||||
Event::dispatch('onPageContentAfter');
|
||||
}
|
||||
|
||||
return static::$page;
|
||||
@@ -220,7 +223,7 @@ class Pages
|
||||
|
||||
// Sort and Slice pages if $raw === false
|
||||
if (!$raw) {
|
||||
$pages = Arr::subvalSort($pages, $order_by, $order_type);
|
||||
$pages = Arr::sort($pages, $order_by, $order_type);
|
||||
|
||||
if ($offset !== null && $length !== null) {
|
||||
$pages = array_slice($pages, $offset, $length);
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Flextype\Component\{Filesystem\Filesystem, Event\Event};
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class Plugins
|
||||
@@ -97,7 +97,7 @@ class Plugins
|
||||
}
|
||||
}
|
||||
|
||||
Events::dispatch('onPluginsInitialized');
|
||||
Event::dispatch('onPluginsInitialized');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Flextype\Component\{Filesystem\Filesystem, View\View};
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class Themes
|
||||
@@ -65,6 +65,29 @@ class Themes
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Themes instance.
|
||||
* Create it if it's not already created.
|
||||
*
|
||||
* @param string $template Template file
|
||||
* @param string $variables Variables
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public static function template(string $template, array $variables = [])
|
||||
{
|
||||
// Set view file
|
||||
// From current theme folder or from plugin folder
|
||||
if (Filesystem::fileExists(THEMES_PATH . '/' . Config::get('site.theme') . '/templates/' . $template . View::$view_ext)) {
|
||||
$template = THEMES_PATH . '/' . Config::get('site.theme') . '/templates/' . $template;
|
||||
} else {
|
||||
$template = PLUGINS_PATH . '/' . $template;
|
||||
}
|
||||
|
||||
// Return template
|
||||
return new View($template, $variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Themes instance.
|
||||
* Create it if it's not already created.
|
||||
|
Reference in New Issue
Block a user