Skip to content

Commit e0c40c1

Browse files
Merge pull request #26 from hexadog/develop
Working with Child Themes
2 parents ec2f7ea + f9d1eed commit e0c40c1

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/Theme.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function getViewPaths($path = ''): array
123123
}
124124
} while ($theme = $theme->getParent());
125125

126-
return $paths;
126+
return array_reverse($paths);
127127
}
128128

129129
/**

src/ThemesManager.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,12 @@ public function clearCache(): bool
9797
* Check if theme with given name exists.
9898
*
9999
* @param string $name
100-
* @param string $vendor
101100
*
102101
* @return bool
103102
*/
104-
public function has(string $name = null)
103+
public function has(string $name = null, ?Collection $themes = null)
105104
{
106-
return !is_null($this->findByName($name));
105+
return !is_null($this->findByName($name, null, $themes));
107106
}
108107

109108
/**
@@ -113,13 +112,13 @@ public function has(string $name = null)
113112
*
114113
* @return mixed
115114
*/
116-
public function get(string $name = null)
115+
public function get(string $name = null, ?Collection $themes = null)
117116
{
118117
if (is_null($name)) {
119118
return $this->themes;
120119
}
121120

122-
return $this->findByName($name);
121+
return $this->findByName($name, null, $themes);
123122
}
124123

125124
/**
@@ -259,7 +258,6 @@ public function image(string $asset, string $alt = '', string $class = '', array
259258
/**
260259
* Get the current theme path to a versioned Mix file.
261260
*
262-
* @param string $path
263261
* @param string $manifestDirectory
264262
* @param mixed $asset
265263
*
@@ -314,13 +312,15 @@ public function filterNonActive(): Collection
314312
*
315313
* @param string $name
316314
*/
317-
protected function findByName(string $name = null, string $vendor = null)
315+
protected function findByName(string $name = null, string $vendor = null, ?Collection $themes = null)
318316
{
319317
if (is_null($name)) {
320318
return null;
321319
}
322320

323-
return $this->themes->first(function ($theme) use ($name, $vendor) {
321+
$themes = $themes ?? $this->themes;
322+
323+
return $themes ? $themes->first(function ($theme) use ($name, $vendor) {
324324
// normalize module name
325325
$name = str_replace(['-theme', 'theme-'], '', $name);
326326
// Check if $name contains vendor
@@ -335,7 +335,7 @@ protected function findByName(string $name = null, string $vendor = null)
335335
}
336336

337337
return $theme->getLowerName() === Str::lower($name) && $theme->getLowerVendor() === Str::lower($vendor);
338-
});
338+
}) : null;
339339
}
340340

341341
/**
@@ -349,15 +349,18 @@ protected function findThemes(): Collection
349349
try {
350350
$themes = $this->scan(Config::get('themes-manager.directory', 'themes'), Theme::class);
351351

352-
$themes->each(function ($theme) {
352+
$themes->each(function ($theme) use ($themes) {
353353
$extendedThemeName = $theme->get('extra.theme.parent');
354354
if ($extendedThemeName) {
355-
if ($this->has($extendedThemeName)) {
356-
$extendedTheme = $this->get($extendedThemeName);
355+
if ($this->has($extendedThemeName, $themes)) {
356+
$extendedTheme = $this->get($extendedThemeName, $themes);
357357
} else {
358358
$extendedTheme = new Theme($theme->getPath());
359359
}
360-
$theme->setParent($extendedTheme);
360+
361+
if ($extendedTheme) {
362+
$theme->setParent($extendedTheme);
363+
}
361364
}
362365
});
363366
} catch (ComposerLoaderException $e) {

0 commit comments

Comments
 (0)