Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/theme config #2665

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/classes/Gantry/Admin/ThemeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Gantry\Admin;

use Gantry\Component\Filesystem\Folder;
use Gantry\Component\Filesystem\Streams;
use Gantry\Component\Theme\ThemeDetails;
use Gantry\Framework\Gantry;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
Expand Down Expand Up @@ -59,23 +60,25 @@ protected static function loadThemes()
foreach ($files as $theme) {
try {
if ($locator('gantry-themes://' . $theme . '/gantry/theme.yaml')) {
$details = new ThemeDetails($theme);
$details->addStreams();
$details = ThemeDetails::instance($theme);

$details['name'] = $theme;
$details['title'] = $details['details.name'];
$details['preview_url'] = $gantry['platform']->getThemePreviewUrl($theme);
$details['admin_url'] = $gantry['platform']->getThemeAdminUrl($theme);
$details['params'] = [];

$list[$details->name] = $details;
$list[$theme] = $details;
}
} catch (\Exception $e) {
// Do not add broken themes into the list.
continue;
}
}

/** @var Streams $streams */
$streams = $gantry['streams'];
$streams->register();

// Add Thumbnails links after adding all the paths to the locator.
foreach ($list as $details) {
$details['thumbnail'] = $details->getUrl("details.images.thumbnail");
Expand Down
23 changes: 12 additions & 11 deletions src/classes/Gantry/Component/Config/CompiledBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ public function modified() {}
/**
* Load the configuration.
*
* @param mixed $data
* @return mixed
*/
public function load()
public function load($data = [])
{
if ($this->object) {
return $this->object;
}

$filename = $this->createFilename();
if (!$this->loadCompiledFile($filename) && $this->loadFiles()) {
$this->saveCompiledFile($filename);
if (!$this->object) {
$data = is_array($data) ? $data : [];
$filename = $this->createFilename();
if (!$this->loadCompiledFile($filename) && $this->loadFiles($data)) {
$this->saveCompiledFile($filename);
}
}

return $this->object;
Expand Down Expand Up @@ -138,7 +138,7 @@ protected function createFilename()
*
* @param array $data
*/
abstract protected function createObject(array $data = []);
abstract protected function createObject(array $data);

/**
* Finalize configuration object.
Expand All @@ -156,12 +156,13 @@ abstract protected function loadFile($name, $filename);
/**
* Load and join all configuration files.
*
* @param array $data
* @return bool
* @internal
*/
protected function loadFiles()
protected function loadFiles(array $data)
{
$this->createObject();
$this->createObject($data);

$list = array_reverse($this->files);
foreach ($list as $files) {
Expand Down
7 changes: 4 additions & 3 deletions src/classes/Gantry/Component/Config/CompiledBlueprints.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CompiledBlueprints extends CompiledBase
*
* @param array $data
*/
protected function createObject(array $data = [])
protected function createObject(array $data)
{
$this->object = new BlueprintSchema($data);
}
Expand Down Expand Up @@ -62,12 +62,13 @@ protected function loadFile($name, $files)
/**
* Load and join all configuration files.
*
* @param array $data
* @return bool
* @internal
*/
protected function loadFiles()
protected function loadFiles(array $data)
{
$this->createObject();
$this->createObject($data);

// Convert file list into parent list.
$list = [];
Expand Down
10 changes: 5 additions & 5 deletions src/classes/Gantry/Component/Config/CompiledConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,22 @@ public function setBlueprints(callable $blueprints)
}

/**
* @param bool $withDefaults
* @param bool|array $data
* @return mixed
*/
public function load($withDefaults = false)
public function load($data = [])
{
$this->withDefaults = $withDefaults;
$this->withDefaults = is_bool($data) ? $data : false;

return parent::load();
return parent::load($data);
}

/**
* Create configuration object.
*
* @param array $data
*/
protected function createObject(array $data = [])
protected function createObject(array $data)
{
if ($this->withDefaults && empty($data) && is_callable($this->callable)) {
$blueprints = $this->callable;
Expand Down
82 changes: 82 additions & 0 deletions src/classes/Gantry/Component/Config/CompiledTheme.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* @package Gantry5
* @author RocketTheme http://www.rockettheme.com
* @copyright Copyright (C) 2007 - 2015 RocketTheme, LLC
* @license Dual License: MIT or GNU/GPLv2 and later
*
* http://opensource.org/licenses/MIT
* http://www.gnu.org/licenses/gpl-2.0.html
*
* Gantry Framework code that extends GPL code is considered GNU/GPLv2 and later
*/

namespace Gantry\Component\Config;

use Gantry\Component\File\CompiledYamlFile;

/**
* The Compiled Configuration class.
*/
class CompiledTheme extends CompiledBase
{
/**
* @var int Version number for the compiled file.
*/
public $version = 1;

/**
* @var Config Configuration object.
*/
protected $object;

/**
* @var callable Blueprints loader.
*/
protected $callable;

/**
* Set blueprints for the configuration.
*
* @param callable $blueprints
* @return $this
*/
public function setBlueprints(callable $blueprints)
{
$this->callable = $blueprints;

return $this;
}

/**
* Create configuration object.
*
* @param array $data
*/
protected function createObject(array $data)
{
$this->object = new Config($data, $this->callable);
}

/**
* Finalize configuration object.
*/
protected function finalizeObject()
{
}

/**
* Load single configuration file and append it to the correct position.
*
* @param string $name Name of the position.
* @param string $filename File to be loaded.
*/
protected function loadFile($name, $filename)
{
if ($name !== 'theme') {
$file = CompiledYamlFile::instance($filename);
$this->object->join($name, $file->content(), '/');
$file->free();
}
}
}