Skip to content

Commit

Permalink
Properly resolve namespaced paths out for themes
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidesu committed Aug 10, 2017
1 parent f4cc553 commit 6c6334f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ThemesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ public function provides()
*/
protected function registerServices()
{
$this->app->singleton('view.finder', function($app) {
return new ThemeViewFinder($app['files'], $app['config']['view.paths'], null);
});

$this->app->singleton('caffeinated.themes', function($app) {
$themes = $this->app['files']->directories(config('themes.paths.absolute'));

Expand All @@ -73,6 +69,10 @@ protected function registerServices()

return new Theme($items);
});

$this->app->singleton('view.finder', function($app) {
return new ThemeViewFinder($app['files'], $app['config']['view.paths'], null);
});
}

/**
Expand Down
36 changes: 36 additions & 0 deletions src/View/ThemeViewFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Caffeinated\Themes\View;

use Theme;
use Illuminate\View\FileViewFinder;

class ThemeViewFinder extends FileViewFinder
Expand All @@ -19,4 +20,39 @@ public function removeLocation(string $location)
unset($this->paths[$key]);
}
}

/**
* Get the path to a template with a named path.
*
* @param string $name
* @return string
*/
protected function findNamespacedView($name)
{
list($namespace, $view) = $this->parseNamespaceSegments($name);

$this->addThemeNamespaceHints($namespace);

return $this->findInPaths($view, $this->hints[$namespace]);
}

/**
* Add namespace hints for the currently set theme.
*
* @param string $namespace
* @return array
*/
protected function addThemeNamespaceHints($namespace)
{
$theme = Theme::getCurrent();

$hints = array_reverse($this->hints[$namespace]);
$hints[] = Theme::absolutePath('views/vendor/'.$namespace);

if (class_exists(\Caffeinated\Modules\Modules::class)) {
$hints[] = Theme::absolutePath('views/modules/'.$namespace);
}

$this->hints[$namespace] = array_reverse($hints);
}
}

0 comments on commit 6c6334f

Please sign in to comment.