Skip to content

Commit

Permalink
Resolve values from augmented values when there is more data to process
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnathonKoster committed Feb 20, 2024
1 parent 693762c commit 55bfaa8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/View/Antlers/Language/Runtime/PathDataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,15 @@ private function checkForValueIntercept($pathItem)
}
}

private function collapseValues(bool $isFinal)
{
if (! $isFinal && $this->reducedVar instanceof Values) {
$this->lockData();
$this->reducedVar = self::reduce($this->reducedVar, true, $this->shouldDoValueIntercept);
$this->unlockData();
}
}

private function collapseQueryBuilder($builder)
{
$this->reducedVar = $builder->get();
Expand Down Expand Up @@ -616,6 +625,8 @@ public function getData(VariableReference $path, $data, $isForArrayIndex = false
$this->unlockData();
}

$this->collapseValues($pathItem->isFinal);

continue;
} else {
if ($this->cascade != null) {
Expand Down Expand Up @@ -660,6 +671,8 @@ public function getData(VariableReference $path, $data, $isForArrayIndex = false

$this->reduceVar($pathItem, $data);

$this->collapseValues($pathItem->isFinal);

if ($pathItem->isFinal && $this->reducedVar instanceof Builder && ! $wasBuilderGoingIntoLast) {
$this->encounteredBuilderOnFinalPart = true;
}
Expand Down
60 changes: 60 additions & 0 deletions tests/Antlers/Runtime/ParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace Tests\Antlers\Runtime;

use Carbon\Carbon;
use Statamic\Fields\Field;
use Statamic\Fields\Value;
use Statamic\Fieldtypes\Group;
use Statamic\Tags\Tags;
use Tests\Antlers\Fixtures\Addon\Tags\EchoMethod;
use Tests\Antlers\Fixtures\Addon\Tags\TestTags as Test;
Expand Down Expand Up @@ -365,4 +368,61 @@ public function index()
'Floats'
);
}

public function test_values_objects_are_resolved_when_processing_tag_params()
{
(new class extends Tags
{
protected static $handle = 'test';

public function index()
{
return $this->params->get('param');
}
})::register();

$theGroup = new Group();

$theField = new Field('the_group', [
'type' => 'group',
'fields' => [
['handle' => 'one', 'field' => ['type' => 'text']],
['handle' => 'two', 'field' => ['type' => 'text']],
],
]);

$theGroup->setField($theField);

$theValue = new Value([
'one' => 'One',
'two' => 'Two',
], 'the_group', $theGroup);

$data = [
'thing' => [
[
'the_group' => $theValue,
],
],
];

$template = <<<'EOT'
{{ thing scope="block" }}
{{ test :param="block:the_group:two" }}
{{ /thing }}
EOT;

$this->assertSame('Two', trim($this->renderString($template, $data, true)));

// Test when the group is the first part of the path.
$data = [
'the_group' => $theValue,
];

$template = <<<'EOT'
{{ test :param="the_group:one" }}
EOT;

$this->assertSame('One', trim($this->renderString($template, $data, true)));
}
}

0 comments on commit 55bfaa8

Please sign in to comment.