Skip to content

Commit

Permalink
Merge pull request #1861 from tomudding/fix/infimum-not-loading-due-t…
Browse files Browse the repository at this point in the history
…o-removal-of-language-aware-api-routing

fix: route assembly not allowing null values for language
  • Loading branch information
tomudding authored Jul 20, 2024
2 parents a09ac27 + 76eaa4c commit 6710a7a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ public function assemble(
// Try to get the language, because we do not have access to the current request in this method we cannot add an
// `else` clause to call `$this->getLanguage()` to get the language.
$language = null;
if (isset($params['language'])) {
if (array_key_exists('language', $params)) {
// The language is already defined in the parameters for the route, so we can use that. This happens when
// calling `url()` from a view while manually setting `['language' => '{language}']`.
// We do not use `isset()` to ensure that we can also do this when we explicitly set the `language` key to
// `null` in the URL builder: `['language' => null]`. This is necessary for routes that do not use the
// language-aware router (i.e. the API), as filtering in the actual route stack definitions to check whether
// the route will hit `/api` is more work.
$language = $params['language'];
} elseif (is_callable([$translator, 'getLocale'])) {
// Otherwise, try to get the language from the translator. Note that `is_callable` is preferred here as
Expand Down
2 changes: 1 addition & 1 deletion module/Application/view/partial/footer.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use Laminas\View\Renderer\PhpRenderer;
<h3><?= $this->translate('Infimum') ?></h3>
<p id="infimum-footer"><?= $this->translate('Loading an infimum...') ?></p>
<script type="text/javascript" nonce="<?= NONCE_REPLACEMENT_STRING ?>">
fetch('<?= $this->url('infimum') ?>')
fetch('<?= $this->url('infimum', ['language' => null]) ?>')
.then(result => result.json())
.then(function (data) {
document.getElementById('infimum-footer').textContent = data['content'];
Expand Down

0 comments on commit 6710a7a

Please sign in to comment.