From 80d0c2a40589b7e354e64f3f9744e7c3477d1bfa Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 22 Jan 2016 10:07:40 +0200 Subject: [PATCH] Blueprint refactor: fix theme thumbnails --- system/src/Grav/Common/Data/Blueprint.php | 46 +++++++++++++++++++++++ system/src/Grav/Common/Themes.php | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Data/Blueprint.php b/system/src/Grav/Common/Data/Blueprint.php index 5bbf3b70a..cb5ec43f7 100644 --- a/system/src/Grav/Common/Data/Blueprint.php +++ b/system/src/Grav/Common/Data/Blueprint.php @@ -51,6 +51,52 @@ class Blueprint extends BaseBlueprints implements ExportInterface return $this; } + + /** + * Get meta value by using dot notation for nested arrays/objects. + * + * @param string $name Dot separated path to the requested value. + * @param string $field Meta field to fetch. + * @param mixed $default Default value (or null). + * @param string $separator Separator, defaults to '.' + * + * @return mixed Value. + */ + public function getMeta($name, $field, $default = null, $separator = '.') + { + $name = $separator != '.' ? strtr($name, $separator, '.') : $name; + + return isset($this->items[$name]['meta'][$field]) ? $this->items[$name]['meta'][$field] : $default; + } + + /** + * Set meta value by using dot notation for nested arrays/objects. + * + * @param string $name Dot separated path to the requested value. + * @param string $field Meta field to fetch. + * @param mixed $value New value. + * @param string $separator Separator, defaults to '.' + */ + public function setMeta($name, $field, $value, $separator = '.') + { + $name = $separator != '.' ? strtr($name, $separator, '.') : $name; + + $this->items[$name]['meta'][$field] = $value; + } + + /** + * Define meta value by using dot notation for nested arrays/objects. + * + * @param string $name Dot separated path to the requested value. + * @param string $field Meta field to fetch. + * @param mixed $value New value. + * @param string $separator Separator, defaults to '.' + */ + public function defMeta($name, $field, $value, $separator = '.') + { + $this->setMeta($name, $field, $this->getMeta($name, $field, $value, $separator), $separator); + } + /** * Return all form fields in a nested list. * diff --git a/system/src/Grav/Common/Themes.php b/system/src/Grav/Common/Themes.php index 2f020f7a4..358275fab 100644 --- a/system/src/Grav/Common/Themes.php +++ b/system/src/Grav/Common/Themes.php @@ -127,7 +127,7 @@ class Themes extends Iterator // Find thumbnail. $thumb = "themes://{$name}/thumbnail.jpg"; if ($path = $this->grav['locator']->findResource($thumb, false)) { - $blueprint->set('thumbnail', $this->grav['base_url'] . '/' . $path); + $blueprint->setMeta('', 'thumbnail', $this->grav['base_url'] . '/' . $path); } $obj = new Data($file->content(), $blueprint);