diff --git a/CHANGELOG.md b/CHANGELOG.md index 12d5c00c8..51ff8001f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Support symlinks when saving `File` 1. [](#bugfix) * Fixed flex objects with integer keys not working [#2863](https://github.com/getgrav/grav/issues/2863) + * Fixed `Pages::instances()` returning null values when using `Flex Pages` [#2889](https://github.com/getgrav/grav/issues/2889) * Fixed user avatar creation for new `Flex Users` when using folder storage * Fixed `Trying to access array offset on value of type null` PHP 7.4 error in `Plugin.php` * Fixed Gregwar Image library using `.jpeg` for cached images, rather use `.jpg` diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 0e2ccce2c..a140f258e 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -748,12 +748,20 @@ class Pages $instance = $this->index[$path] ?? null; if (\is_string($instance)) { $instance = $this->directory ? $this->directory->getObject($instance, 'flex_key') : null; - if ($instance && $this->fire_events && method_exists($instance, 'initialize')) { - $instance->initialize(); + if ($instance) { + if ($this->fire_events && method_exists($instance, 'initialize')) { + $instance->initialize(); + } + } else { + /** @var Debugger $debugger */ + $debugger = $this->grav['debugger']; + $debugger->addMessage(sprintf('Flex page %s is missing or broken!', $instance), 'debug'); } } - $this->instances[$path] = $instance; + if ($instance) { + $this->instances[$path] = $instance; + } return $instance; }