From 1a0f6a5809db7350a5b3bd747816dda0f2898782 Mon Sep 17 00:00:00 2001 From: Jan Hug Date: Fri, 7 Aug 2020 09:28:57 +0200 Subject: [PATCH 1/2] Correct context for multiple sources in destination --- src/Element/Pattern.php | 7 ++++--- src/Element/PatternContext.php | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Element/Pattern.php b/src/Element/Pattern.php index e04ea99a..2bf170a5 100644 --- a/src/Element/Pattern.php +++ b/src/Element/Pattern.php @@ -156,13 +156,14 @@ public static function processMultipleSources(array $element) { if (count($field) > 1) { /** @var \Drupal\ui_patterns\Element\PatternContext $context */ $context = $element['#context']; - $context->setProperty('pattern', $element['#id']); - $context->setProperty('field', $name); + $field_context = new PatternContext($context->getType(), $context->getProperties()); + $field_context->setProperty('pattern', $element['#id']); + $field_context->setProperty('field', $name); // Render multiple sources with "patterns_destination" template. $element['#fields'][$name] = [ '#sources' => $field, - '#context' => $context, + '#context' => $field_context, '#theme' => 'patterns_destination', ]; } diff --git a/src/Element/PatternContext.php b/src/Element/PatternContext.php index 48f0ab34..6f7834b7 100644 --- a/src/Element/PatternContext.php +++ b/src/Element/PatternContext.php @@ -49,6 +49,16 @@ public function getProperty($name) { return isset($this->properties[$name]) ? $this->properties[$name] : NULL; } + /** + * Get pattern context properties. + * + * @return mixed + * Property value. + */ + public function getProperties() { + return $this->properties; + } + /** * Set pattern context property. * From 7541ce7326e1673c07e0a290fc58e4c1475ed2cb Mon Sep 17 00:00:00 2001 From: Jan Hug Date: Fri, 7 Aug 2020 09:38:03 +0200 Subject: [PATCH 2/2] Adjust comment --- src/Element/PatternContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Element/PatternContext.php b/src/Element/PatternContext.php index 6f7834b7..911abb4a 100644 --- a/src/Element/PatternContext.php +++ b/src/Element/PatternContext.php @@ -53,7 +53,7 @@ public function getProperty($name) { * Get pattern context properties. * * @return mixed - * Property value. + * All context properties. */ public function getProperties() { return $this->properties;