From f7f8aa108abca5fe7bb1ef886167a985f08be1e6 Mon Sep 17 00:00:00 2001 From: Gert Date: Mon, 4 May 2015 19:27:44 +0200 Subject: [PATCH] allow custom context for extending blueprints --- system/src/Grav/Common/Data/Blueprints.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Data/Blueprints.php b/system/src/Grav/Common/Data/Blueprints.php index a92f235f2..84d9ce486 100644 --- a/system/src/Grav/Common/Data/Blueprints.php +++ b/system/src/Grav/Common/Data/Blueprints.php @@ -2,6 +2,7 @@ namespace Grav\Common\Data; use Grav\Common\File\CompiledYamlFile; +use Grav\Common\GravTrait; /** * Blueprints class keeps track on blueprint instances. @@ -11,6 +12,8 @@ use Grav\Common\File\CompiledYamlFile; */ class Blueprints { + use GravTrait; + protected $search; protected $types; protected $instances = array(); @@ -55,8 +58,20 @@ class Blueprints if (isset($blueprints['@extends'])) { // Extend blueprint by other blueprints. $extends = (array) $blueprints['@extends']; - foreach ($extends as $extendType) { - $blueprint->extend($this->get($extendType)); + + if (is_string(key($extends))) { + $extends = [ $extends ]; + } + + foreach ($extends as $extendConfig) { + $type = !is_string($extendConfig) ? empty($extendConfig['type']) ? false : $extendConfig['type'] : $extendConfig; + + if (!$type) { + continue; + } + + $context = is_string($extendConfig) || empty($extendConfig['context']) ? $this : new self(self::getGrav()['locator']->findResource($extendConfig['context'])); + $blueprint->extend($context->get($type)); } }