AugustMiller / kirby-place-field

Deprecated! A simple Google Maps field for Kirby CMS. Please use my Map Field plugin, instead:
https://github.com/AugustMiller/kirby-map-field
21 stars 3 forks source link

Field options are not accepted #4

Closed rafegoldberg closed 9 years ago

rafegoldberg commented 9 years ago

So I'm using the place field and it works almost perfectly. The only issue I have is that I haven't been able to set the default zoom despite following the README's example almost to the letter:

fields:
   address:
      label: Address
      type: place
      center:
         lat: 45.5230622
         lng: -122.67648159999999
         zoom: 13
      help: >
         Look up an address or location.

So if the issue isn't stemming from the blueprint file any ideas what might be causing the issue? or even better: how to go about fixing it? Thanks for the dope little Kirby extension.

PaulMorel commented 9 years ago

I've had this too. Default zoom is always 1 for some reason. The plugin doesn't seem to take the center setting in its blueprint.

What I did to fix it was to set the default lat, lng and zoom in the config.php file of my Kirby install.

So how about you try adding this to your config.php file.

c::set('place.defaults.lat', 45.5230622);
c::set('place.defaults.lng', -122.67648159999999);
c::set('place.defaults.zoom', 13);
AugustMiller commented 9 years ago

Sorry, @rafegoldberg! I didn't see this until just now.

Totally correct— a huge oversight, on my part. I must have thought the values were coming in, correctly, but been mistaken.

Unfortunately, after a bit of exploration, the automatic setters for these options is more complicated to set up than I'd thought, and wasn't happening at all, actually.

It may take a bit for me to get around to this fix, but the temporary patch @PaulMorel provided will work as expected.

The downside, here, of course, is that all maps on the site will default to the same location, as defined in your config.php.

rafegoldberg commented 9 years ago

Thanks @PaulMorel for the tip; hard coding the values won't be a problem for this project. And yeah, I've used Google Maps plugins a number of CMS systems and they've always had issues with default zoom so I'd imagine it's harder than it seems!

AugustMiller commented 9 years ago

Updated the name to reflect the larger issue at play. Investigating, this week!

I've also submitted a query on the forums to see if anyone can help with the underlying custom field settings logic.

PaulMorel commented 9 years ago

Good news! I made it work. center being the main problem. Here's a blueprint that works:

  coordinates:
    label: Coordinates
    type: place
    map_settings:
      lat: 45.2501566
      lng: -75.8002568
      zoom: 10
    help: Move the pin wherever you'd like, or search for a location!

I checked out the source for the plugin and saw that map_settings was the property that contained lat, lng and zoom. If I use map_settings instead of center in my blueprints, it works.

My understanding is that when we use the center property, it doesn't replace the defaults because exchange of information between map_settings and center happens on the __construct method. If I understand correctly, __construct happens way before blueprint settings get propagated into the class. (I might be wrong, as I have limited understanding of OOP).

So I think this is the problem:

if (isset($this->center)) {
    $this->map_settings = array_merge($this->map_settings, (array)$this->center);
}

If you replace any mention of map_settings with center it should work as intended.

rafegoldberg commented 9 years ago

Will try with my install and report back. Thanks for the tips guys; been loving Kirby as a Wordpress alternative so hoping this plugin/exchange is indicative of where the community is at as a whole!

AugustMiller commented 9 years ago

@PaulMorel: I just pushed an update that may address this. Would the two of you mind pulling down the latest place.php and check it out?

I've basically deferred the merging of custom options into the defaults until the form is rendered, rather than when the field is instantiated. I think that this observation was on point:

If I understand correctly, __construct happens way before blueprint settings get propagated into the class.

How you arrived at that, I don't know. :wink: Yet— the constructor is clearly not invoking any sort of rendering method (content()) internally, so there must be another place in Kirby core that injects data and kicks off that process.

Still feels wrong, to me. ¯_(ツ)_/¯

rafegoldberg commented 9 years ago

dope, just pulled down update and like (well planned) magic the map now appears to respect the blueprint center arg. results of setting the zoom to 5 and 15, respectively:

image image

rafegoldberg commented 9 years ago

@AugustMiller also thanks for the quick turnaround yo; thanks for the work on this!

AugustMiller commented 9 years ago

:ok_hand: You got it.

PaulMorel commented 9 years ago

Woo, I helped fix a bug! Thanks for the hard work @AugustMiller

rafegoldberg commented 9 years ago

:+1: @PaulMorel