Closed boxadesign closed 5 years ago
Hi @boxadesign did you find something for your issue ?
Here’s how you could do this as of Craft 3.5 or later:
use craft\elements\Entry;
use craft\helpers\ArrayHelper;
'transformer' => function(Entry $entry) {
return [
'title' => $entry->title,
'slugs' => array_map(function(Entry $loc) {
return $loc->slug;
}, ArrayHelper::index($entry->getLocalized()->all(), 'site.handle')),
];
}
I am using the element-api to get entries. What I would like to do is have the slug of entries in the other languages in the data that correspond with ID of each entry. This is so I can use this in my static site generator to create a language switcher. Ideally I'd like to get an array of slugs for all entries with the same ID. I'd like to get back something like this:
My current simple endpoint is below: