From eccf96222dacb6e58b4cc478eca8f05568809341 Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Tue, 24 Jun 2014 18:37:42 +1000 Subject: [PATCH] Components now support a shared /components/partials directory used as a fallback when a partial is not found. --- CHANGELOG.md | 3 +++ modules/cms/classes/ComponentBase.php | 4 ++-- modules/cms/classes/ComponentPartial.php | 16 +++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da270928e..abfa164c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +* **Build 111** (2014-06-xx) + - Components now support a shared `/partials` directory used as a fallback when a partial is not found. + * **Build 110** (2014-06-24) - Created a new Grid form widget for managing tabular data. - Widget identifiers have changed to remove the alias if it matches the default alias. diff --git a/modules/cms/classes/ComponentBase.php b/modules/cms/classes/ComponentBase.php index 1bf7e700c..2a37180d6 100644 --- a/modules/cms/classes/ComponentBase.php +++ b/modules/cms/classes/ComponentBase.php @@ -74,7 +74,7 @@ abstract class ComponentBase extends Extendable $className = Str::normalizeClassName(get_called_class()); $this->dirName = strtolower(str_replace('\\', '/', $className)); - $this->assetPath = Config::get('cms.pluginsDir') . dirname(dirname($this->dirName)); + $this->assetPath = Config::get('cms.pluginsDir').dirname(dirname($this->dirName)); parent::__construct(); } @@ -89,7 +89,7 @@ abstract class ComponentBase extends Extendable */ public function getPath() { - return base_path() . Config::get('cms.pluginsDir') . $this->dirName; + return base_path().Config::get('cms.pluginsDir').$this->dirName; } /** diff --git a/modules/cms/classes/ComponentPartial.php b/modules/cms/classes/ComponentPartial.php index e70f1125b..7e6238c29 100644 --- a/modules/cms/classes/ComponentPartial.php +++ b/modules/cms/classes/ComponentPartial.php @@ -1,5 +1,7 @@ getPath().'/'.$fileName; + $path = $component->getPath().'/'.$fileName; + + /* + * Check the shared "/partials" directory for the partial + */ + if (!File::isFile($path)) { + $sharedDir = dirname($component->getPath()).'/partials'; + $sharedPath = $sharedDir.'/'.$fileName; + if (File::isFile($sharedPath)) + return $sharedPath; + } + + return $path; } }