craftcms / element-api

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

Color field return an empty object #67

Closed SebastianoOlivo closed 6 years ago

SebastianoOlivo commented 6 years ago

Hello,

When I try to get the value of a color field I get back an empty Object :

entry => colorFieldName,

Since this case is note documented, I have no idea if it's a bug or just the wrong way to get back the hexadecimal info of a color from a color field.

Could you please check this ?

Kr,

Sebastiano

brandonkelly commented 6 years ago

Color fields will return a craft\fields\data\ColorData object. You can either cast it to a string or call its getHex() function:

'option1' => (string)$entry->colorField,
'option2' => $entry->colorField->getHex(),
SebastianoOlivo commented 6 years ago

Thanks for this clarification Brandon. It work like a charm !