My custom views’s field returns JSON as a string:
"order_line_items": "[{"sku":"GC2","quantity":"5.00","price":"50.00"},{"sku":"SGBLEND","quantity":"1.00","price":"6.00"},{"sku":"NAV1STYR","quantity":"1.00","price":"9.50"}]",
I hope to get rid of the surrounding quotation (") marks.
This is how the field is created
class OrderLineItems extends FieldPluginBase { public function usesGroupBy() { return FALSE; } public function query() { // Do nothing -- to override the parent query. } public function render(ResultRow $values) { $order = $this->getEntity($values); $details = []; foreach ($order->getItems() as $order_item) { $product_sku = $order_item->getPurchasedEntity()->getSku(); $product_quantity = $order_item->getQuantity(); $product_price = $order_item->getUnitPrice()->getNumber(); $order_item_array = [ 'sku' => $product_sku, 'quantity' => $product_quantity, 'price' => number_format((float)$product_price, 2, '.', '') ]; $details[] = $order_item_array; } return json_encode($details); return $details; } }
I haven’t found how can I add formatter for this custom field, to make this JSON output valid. I did some reasearch, and I have found that there a module module tak can make it for a real fields, but not for the custom views’s field.