From b576571d65e89a9497b790b46a576f70577ea881 Mon Sep 17 00:00:00 2001 From: gggeek Date: Mon, 14 May 2018 16:27:56 +0100 Subject: [PATCH] fixes for tags and for array refs --- Core/Executor/ContentManager.php | 5 +++++ Core/Executor/TagManager.php | 1 + Core/FieldHandlerManager.php | 22 +++++++++++++++++++ .../EmbeddedRegexpReferenceResolverTrait.php | 5 ++++- 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Core/Executor/ContentManager.php b/Core/Executor/ContentManager.php index 24e469cc..6a637862 100644 --- a/Core/Executor/ContentManager.php +++ b/Core/Executor/ContentManager.php @@ -677,7 +677,12 @@ protected function setMainLocation(Content $content, $locationId) protected function getFieldValue($value, FieldDefinition $fieldDefinition, $contentTypeIdentifier, array $context = array()) { $fieldTypeIdentifier = $fieldDefinition->fieldTypeIdentifier; + if (is_array($value) || $this->fieldHandlerManager->managesField($fieldTypeIdentifier, $contentTypeIdentifier)) { + // since we now allow refs to be arrays, let's attempt a 1st pass at resolving them here instead of every single fieldHandler... + if (is_string($value) && $this->fieldHandlerManager->doPreResolveStringReferences($fieldTypeIdentifier, $contentTypeIdentifier)) { + $value = $this->referenceResolver->resolveReference($value); + } // inject info about the current content type and field into the context $context['contentTypeIdentifier'] = $contentTypeIdentifier; $context['fieldIdentifier'] = $fieldDefinition->identifier; diff --git a/Core/Executor/TagManager.php b/Core/Executor/TagManager.php index 72d3bfd7..0f737b0b 100644 --- a/Core/Executor/TagManager.php +++ b/Core/Executor/TagManager.php @@ -183,6 +183,7 @@ protected function matchTags($action, $step) */ protected function getReferencesValues($tag, array $references, $step) { + $lang = $this->getLanguageCode($step); $refs = array(); foreach ($references as $reference) { diff --git a/Core/FieldHandlerManager.php b/Core/FieldHandlerManager.php index cb2f4806..baaf3d27 100644 --- a/Core/FieldHandlerManager.php +++ b/Core/FieldHandlerManager.php @@ -48,6 +48,28 @@ public function managesField($fieldTypeIdentifier, $contentTypeIdentifier) isset($this->fieldTypeMap['*'][$fieldTypeIdentifier])); } + /** + * Returns true when a fieldHandler allows string refs to be pre-resolved for the field value it gets as hash. + * "pre-resolved" means: resolved before the field-handler-specific propcessing kicks in + * + * @param string $fieldTypeIdentifier + * @param string $contentTypeIdentifier + */ + public function doPreResolveStringReferences($fieldTypeIdentifier, $contentTypeIdentifier) + { + if (!$this->managesField($fieldTypeIdentifier, $contentTypeIdentifier)) { + return true; + } + + $fieldHandler = $this->getFieldHandler($fieldTypeIdentifier, $contentTypeIdentifier); + // BC: not alwys defined + if (is_callable(array($fieldHandler, 'doPreResolveStringReferences'))) { + return $fieldHandler->doPreResolveStringReferences(); + } + + return true; + } + /** * @param string $fieldTypeIdentifier * @param string $contentTypeIdentifier diff --git a/Core/ReferenceResolver/EmbeddedRegexpReferenceResolverTrait.php b/Core/ReferenceResolver/EmbeddedRegexpReferenceResolverTrait.php index f4405276..4e7388f1 100644 --- a/Core/ReferenceResolver/EmbeddedRegexpReferenceResolverTrait.php +++ b/Core/ReferenceResolver/EmbeddedRegexpReferenceResolverTrait.php @@ -26,6 +26,7 @@ public function hasEmbeddedReferences($string) * * @param string $string * @return string + * @todo q: if reference is an array, should we recurse on it ? */ public function resolveEmbeddedReferences($string) { @@ -35,7 +36,9 @@ public function resolveEmbeddedReferences($string) if ($count) { foreach ($matches[0] as $referenceIdentifier) { $reference = $this->getReferenceValue(substr($referenceIdentifier, 1, -1)); - $string = str_replace($referenceIdentifier, $reference, $string); + if (is_string($reference)) { + $string = str_replace($referenceIdentifier, $reference, $string); + } } }