craftcms / element-api

Create a JSON API/Feed for your elements in Craft.
MIT License
498 stars 56 forks source link

Requesting a draft sends it only in the primary language #108

Closed pablofernandezgh closed 4 years ago

pablofernandezgh commented 4 years ago

When requesting a draft, I only see it in the primary language of my website. According to the docs, when setting a draftId the criteria gets ignored. Then how am I supposed to get this draft in a different locale ?

Here's my query

return [
    'class' => EntryResource::class,
    'criteria' => ['section' => 'homepageAds', 'site' => $site],
    'paginate' => false,
    'draftId' => $draftId,
    'transformer' => new HomepageAdsTransformer($version)
];
brandonkelly commented 4 years ago

Before Craft 3.2, drafts were only available in the one site that they were created in.

In Craft 3.2+, EntryResource is actually no longer needed. So you can drop your class and draftId settings, and move $draftId to the criteria:

return [
    'elementType' => craft\elements\Entry::class,
    'criteria' => [
        'drafts' => true,
        'draftId' => $draftId;
        'section' => 'homepageAds',
        'site' => $site,
    ],
    'paginate' => false,
    'transformer' => new HomepageAdsTransformer($version)
];
brandonkelly commented 4 years ago

Just released Element API 2.6.0 which deprecates EntryResource and removes the section in the README about it.