Skip to content

Commit

Permalink
[4.x] Fix locales tag inside replicator, bard, and grid (#9566)
Browse files Browse the repository at this point in the history
  • Loading branch information
aerni authored Feb 22, 2024
1 parent 78d8f4b commit 108b9e5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Tags/Locales.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private function getData()
return $this->data;
}

$id = $this->params->get('id', $this->context->value('id'));
$id = $this->params->get('id') ?? $this->context->value('page.id') ?? $this->context->value('id');

$data = Data::find($id);

Expand Down
32 changes: 32 additions & 0 deletions tests/Tags/LocalesTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,36 @@ public function it_displays_nothing_when_context_id_is_null()
$this->tag('{{ locales }}you should not see this{{ /locales }}', ['id' => $value])
);
}

/** @test */
public function it_prefers_page_id_over_id()
{
(new EntryFactory)
->collection('test')
->locale('english')
->id('1')
->data(['title' => 'hello'])
->create();

$this->assertEquals(
'<hello>',
$this->tag('{{ locales }}<{{ title }}>{{ /locales }}', ['page' => ['id' => '1']])
);
}

/** @test */
public function it_prefers_id_param_over_page_id()
{
(new EntryFactory)
->collection('test')
->locale('english')
->id('1')
->data(['title' => 'hello'])
->create();

$this->assertEquals(
'<hello>',
$this->tag('{{ locales id="1" }}<{{ title }}>{{ /locales }}', ['page' => ['id' => '7']])
);
}
}

0 comments on commit 108b9e5

Please sign in to comment.