From b641b0e442ae15bdc3ae7cee3103c6a5a50ef78e Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Mon, 7 Oct 2019 13:45:49 +0300 Subject: [PATCH] Fixed `Flex Pages` not calling `onPageProcessed` event when cached --- CHANGELOG.md | 1 + system/src/Grav/Common/Page/Pages.php | 14 ++++++++++++-- .../Console/Cli/PageSystemValidatorCommand.php | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01e7d8cbe..5fd47c2d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 1. [](#bugfix) * Fixed `Page::untranslatedLanguages()` not being symmetrical to `Page::translatedLanguages()` + * Fixed `Flex Pages` not calling `onPageProcessed` event when cached # v1.7.0-beta.10 ## 10/03/2019 diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index ba5cc85e0..0abe91288 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -702,7 +702,12 @@ class Pages $instance = $this->instances[(string)$path] ?? null; if (\is_string($instance)) { $instance = $this->flex ? $this->flex->getObject($instance) : null; - $instance = $instance->hasTranslation() ? $instance->getTranslation() : $instance; + if ($instance) { + $instance = $instance->hasTranslation() ? $instance->getTranslation() : $instance; + if (method_exists($instance, 'initialize') && $this->grav['config']->get('system.pages.events.page')) { + $instance->initialize(); + } + } } if ($instance && !$instance instanceof PageInterface) { throw new \RuntimeException('Routing failed on unknown type', 500); @@ -1325,7 +1330,12 @@ class Pages */ foreach ($collection as $key => $page) { if ($config->get('system.pages.events.page')) { - $this->grav->fireEvent('onPageProcessed', new Event(['page' => $page])); + if (method_exists($page, 'initialize')) { + $page->initialize(); + } else { + // TODO: Deprecated, only used in 1.7 betas. + $this->grav->fireEvent('onPageProcessed', new Event(['page' => $page])); + } } $path = $page->path(); diff --git a/system/src/Grav/Console/Cli/PageSystemValidatorCommand.php b/system/src/Grav/Console/Cli/PageSystemValidatorCommand.php index a8845a47d..9d9e1cc3b 100644 --- a/system/src/Grav/Console/Cli/PageSystemValidatorCommand.php +++ b/system/src/Grav/Console/Cli/PageSystemValidatorCommand.php @@ -170,6 +170,7 @@ class PageSystemValidatorCommand extends ConsoleCommand // Pages $grav['pages']->init(); $grav->fireEvent('onPagesInitialized', new Event(['pages' => $grav['pages']])); + $grav->fireEvent('onPageInitialized', new Event(['page' => $grav['page']])); if ($this->input->getOption('record')) { $this->output->writeln('Pages: ' . $config->get('system.pages.type', 'page'));