Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Fix locales tag inside replicator, bard, and grid #9566

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']])
);
}
}
Loading