diff --git a/modules/cms/twig/Loader.php b/modules/cms/twig/Loader.php index d3fe3475b..c0b1dc10a 100644 --- a/modules/cms/twig/Loader.php +++ b/modules/cms/twig/Loader.php @@ -27,7 +27,9 @@ class Loader extends LoaderBase implements TwigLoaderInterface /** * Sets a CMS object to load the template from. + * * @param \Cms\Contracts\CmsObject $obj Specifies the CMS object. + * @return void */ public function setObject(CmsObject $obj) { @@ -37,6 +39,9 @@ class Loader extends LoaderBase implements TwigLoaderInterface /** * Returns the Twig content string. * This step is cached internally by Twig. + * + * @param string $name The template name + * @return TwigSource */ public function getSourceContext($name) { @@ -65,6 +70,9 @@ class Loader extends LoaderBase implements TwigLoaderInterface /** * Returns the Twig cache key. + * + * @param string $name The template name + * @return string */ public function getCacheKey($name) { @@ -77,6 +85,10 @@ class Loader extends LoaderBase implements TwigLoaderInterface /** * Determines if the content is fresh. + * + * @param string $name The template name + * @param mixed $time The time to check against the template + * @return bool */ public function isFresh($name, $time) { @@ -89,6 +101,9 @@ class Loader extends LoaderBase implements TwigLoaderInterface /** * Returns the file name of the loaded template. + * + * @param string $name The template name + * @return string */ public function getFilename($name) { @@ -101,6 +116,9 @@ class Loader extends LoaderBase implements TwigLoaderInterface /** * Checks that the template exists. + * + * @param string $name The template name + * @return bool */ public function exists($name) { @@ -115,11 +133,12 @@ class Loader extends LoaderBase implements TwigLoaderInterface * Internal method that checks if the template name matches * the loaded object, with fallback support to partials. * + * @param string $name The template name to validate * @return bool */ protected function validateCmsObject($name) { - if ($name === $this->obj->getFilePath()) { + if ($this->obj && $name === $this->obj->getFilePath()) { return true; } @@ -133,18 +152,29 @@ class Loader extends LoaderBase implements TwigLoaderInterface /** * Looks up a fallback CMS partial object. - * @return Cms\Classes\Partial + * + * @param string $name The filename to attempt to load a fallback CMS partial for + * @return Cms\Classes\Partial|bool Returns false if a CMS partial can't be found */ protected function findFallbackObject($name) { + // Ignore Laravel views if (strpos($name, '::') !== false) { return false; } + // Check the cache if (array_key_exists($name, $this->fallbackCache)) { return $this->fallbackCache[$name]; } - return $this->fallbackCache[$name] = CmsPartial::find($name); + // Attempt to load the path as a CMS Partial object + try { + $partial = CmsPartial::find($name); + } catch (\Exception $e) { + return false; + } + + return $this->fallbackCache[$name] = $partial; } }