elivz / VzAddress-Craft

Address fieldtype for the Craft CMS
30 stars 13 forks source link

How can I use this field with Element API? #10

Closed ghost closed 7 years ago

ghost commented 8 years ago

I have VZ Address on my site and I'm trying to expose data stored in it via the Element API plugin. However, when I use the following endpoint config the address returned is "null":

    'v1/locations/<entryId:\d+>.json' => function($entryId) {
      return [
        'elementType' => 'Entry',
        'criteria' => ['id' => $entryId],
        'first' => true,
        'transformer' => function(EntryModel $entry) {
          return [
            'title' => $entry->title,
            'url' => $entry->url,
            'address' => $entry->address
          ];
        },
      ];
    },
elivz commented 8 years ago

Try this:

'address' => $entry->address->toArray(),