Components now support a shared /components/partials directory used as a fallback when a partial is not found.

This commit is contained in:
Sam Georges 2014-06-24 18:37:42 +10:00
parent 070667ebe0
commit eccf96222d
3 changed files with 20 additions and 3 deletions

View File

@ -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) * **Build 110** (2014-06-24)
- Created a new Grid form widget for managing tabular data. - Created a new Grid form widget for managing tabular data.
- Widget identifiers have changed to remove the alias if it matches the default alias. - Widget identifiers have changed to remove the alias if it matches the default alias.

View File

@ -74,7 +74,7 @@ abstract class ComponentBase extends Extendable
$className = Str::normalizeClassName(get_called_class()); $className = Str::normalizeClassName(get_called_class());
$this->dirName = strtolower(str_replace('\\', '/', $className)); $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(); parent::__construct();
} }
@ -89,7 +89,7 @@ abstract class ComponentBase extends Extendable
*/ */
public function getPath() public function getPath()
{ {
return base_path() . Config::get('cms.pluginsDir') . $this->dirName; return base_path().Config::get('cms.pluginsDir').$this->dirName;
} }
/** /**

View File

@ -1,5 +1,7 @@
<?php namespace Cms\Classes; <?php namespace Cms\Classes;
use File;
/** /**
* The CMS component partial class. * The CMS component partial class.
* *
@ -49,6 +51,18 @@ class ComponentPartial extends CmsObject
*/ */
public static function getFilePath($component, $fileName) public static function getFilePath($component, $fileName)
{ {
return $component->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;
} }
} }