Skip to content

Commit

Permalink
fixes for tags and for array refs
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed May 14, 2018
1 parent 0840957 commit b576571
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Core/Executor/ContentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Core/Executor/TagManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 22 additions & 0 deletions Core/FieldHandlerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
}
}
}

Expand Down

0 comments on commit b576571

Please sign in to comment.