doublesecretagency / craft-googlemaps

Google Maps plugin for Craft CMS - Maps in minutes. Powered by the Google Maps API.
https://plugins.doublesecretagency.com/google-maps/
Other
10 stars 9 forks source link

Call to a member function getSettings() on null #62

Closed jpcarpenter closed 2 years ago

jpcarpenter commented 2 years ago

I am getting this error when attempting to use the visitor geolocation helper within the element api plugin. I've recently upgraded from smartmaps to the new googlemaps, and updated the relevant code to adhere to the new plugin.

The error:

Error: Call to a member function getSettings() on null
in /app/vendor/doublesecretagency/craft-googlemaps/src/helpers/GeolocationHelper.php at line 37

// Set geolocation service
$selected = GoogleMapsPlugin::$plugin->getSettings()->geolocationService

How I'm setting/calling the method:

use doublesecretagency\googlemaps\helpers\GoogleMaps;

if (!Craft::$app->getRequest()->getIsConsoleRequest()) {
   // Where the error is being thrown
   $visitor = GoogleMaps::getVisitor();
}

Craft CMS: 3.7.33 Google Maps: 4.1.9 Element API: 2.8.6.1

lindseydiloreto commented 2 years ago

That's interesting. For whatever reason, it's saying that GoogleMapsPlugin::$plugin is null. It doesn't quite make sense, because GoogleMapsPlugin::$plugin should be getting set very early and very consistently.

I'm about to leave town for a week, but I'm happy to troubleshoot this when I get back. Will let you know how it goes!

jpcarpenter commented 2 years ago

This ended up being an issue with updating Craft from 3.7.30.1 to 3.7.33. Apparently there was a "allow-plugins" config setting that needed to be added to the composer.json file that previous versions didn't need. Without it, all plugins "seemed" like they were being installed properly, but turns out they weren't being installed at all. The GoogleMaps plugin was just the first one to complain about it, which is why I assumed it had something to do with the plugin itself.

Once I figured this out, adding the following to my composer.json and running composer install fixed the issue:

"config": {
    "allow-plugins": {
      "yiisoft/yii2-composer": true,
      "craftcms/plugin-installer": true
    }
  }
lindseydiloreto commented 2 years ago

Ah, good to hear. Glad you got it sorted, thanks for reporting back! 👍