getLatLngFromSource = $getLatLngFromSource; } /** * Calculate latitude and longitude using google map if api key is defined * * @param SourceRepositoryInterface $subject * @param SourceInterface $source * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeSave( SourceRepositoryInterface $subject, SourceInterface $source ): array { if (!$source->getLatitude() && !$source->getLongitude()) { try { $latLng = $this->getLatLngFromSource->execute($source); $source->setLatitude($latLng->getLat()); $source->setLongitude($latLng->getLng()); } catch (\Exception $e) { unset($e); // Silently fail geo coding } } return [$source]; } }