/** * {@inheritdoc} */ public function getSourceFields($url) { $items = parent::getSourceFields($url); $return = []; // Loop over the JSON values and extract types // as individual rows. foreach ($items as &$item) { if (isset($item['types']) && is_array($item['types'])) { foreach ($item['types'] as $type) { // We need to use place_id as the identifier for parsing JSON // in the parent class. // But we are really wanting to import an individual type // only once. So over-write the place_id with the type. $return[] = ['place_id' => $type, 'type' => $type]; } } } return $return; }
/** * {@inheritdoc} */ public function getSourceFields($url) { $items = parent::getSourceFields($url); // Loop over the JSON values, walk the tree and extract as keyed values. foreach ($items as &$item) { if (isset($item['address_components']) && is_array($item['address_components'])) { foreach ($item['address_components'] as $component) { if (isset($component['long_name']) && isset($component['types']) && is_array($component['types'])) { foreach ($component['types'] as $type) { $item[$type] = $component['long_name']; } } } } if (isset($item['geometry']['location']['lat'])) { $item['lat'] = $item['geometry']['location']['lat']; } if (isset($item['geometry']['location']['lng'])) { $item['lng'] = $item['geometry']['location']['lng']; } } return $items; }