Skip to content

Not able to build an Entry with locale=* and benefit from locale fallback #270

@pugbyte

Description

Hello,

I'm trying to build an Entry with locale=* and then output that Entry by using Entry->all() with the non-default locale. I expected this to work, but to my dismay it actually throws an InvalidArgumentException. The problem is here, in Resource/Entry.php:

// getUnresolvedField
if (\array_key_exists($locale, $value)) {
    return $value[$locale];
}
if (!$field->isLocalized()) {
    throw new \InvalidArgumentException(\sprintf(
        'Trying to access the non-localized field "%s" on content type "%s" using the non-default locale "%s".',
        $field->getName(),
        $this->sys->getContentType()->getName(),
        $locale
    ));
}
$locale = $this->walkFallbackChain($value, $locale, $this->sys->getEnvironment());

As you can see, the SDK checks to see if a field is marked as localizable before it attempts to walk the fallback chain for locales. This makes it impossible to build (and more importantly: PSR-6 cache) an Entry object with all locales and then output it in one locale, forcing me to make an API call for each locale for a given Entry ID.

Is there a chance that this behaviour could be revised?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions