Skip to content

Commit

Permalink
fix(locale-links): Fix locale handling when fetching link resources
Browse files Browse the repository at this point in the history
  • Loading branch information
dborsatto committed Nov 9, 2018
1 parent 3bde167 commit f975976
Show file tree
Hide file tree
Showing 12 changed files with 2,513 additions and 137 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased](https://github.com/contentful/contentful.php/compare/4.0.1...HEAD)

### Fixed

* Resolving links from an entry using non-default locale caused the SDK to wrongly assume the `locale=*`. Now this is fixed, and the entry will use either its current locale, if set, or the the `locale=*` if no locales are currently configured.

## [4.0.1](https://github.com/contentful/contentful.php/tree/4.0.1) (2018-11-08)

### Fixed
Expand Down
9 changes: 5 additions & 4 deletions src/Resource/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,12 @@ private function getUnresolvedField(Field $field, string $locale = \null)
*/
private function resolveFieldLinks($field, string $locale = \null)
{
// If there is no locale, it means the current entry
// has been requested using the * locale, so we explicitly set it
// to avoid issues with the resource pool
// If no locale is set, to resolve links we use either the special "*" locale,
// or the default one, depending whether this entry was built using a locale or not
if (\null === $locale) {
$locale = '*';
$locale = \null === $this->sys->getLocale()
? '*'
: $this->getLocale();
}

if ($field instanceof Link) {
Expand Down
2 changes: 2 additions & 0 deletions src/Resource/LocalizedResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public function setLocale($locale)

/**
* The locale code for the currently set locale.
* It will be either the default locale if the resource was fetched using "locale=*",
* or the one that was used in the API request.
*
* @return string
*/
Expand Down
Loading

0 comments on commit f975976

Please sign in to comment.