adrian Posted March 14, 2014 Share Posted March 14, 2014 (edited) Hi everyone, Here's something I have been battling with. I am trying to create a new page via the API with a template that contains a MapMarker field. The template also contains two other custom field types (phone and dimensions, which are both fine). The problem comes down to the fact that the lat and lng subfields of the MapMarker fieldtype are floats. So, when you try to save the page, you get the following error: Warning: 1265 Data truncated for column 'lat' at row 1 which makes complete sense. Here is the generated SQL: INSERT INTO `field_map` (pages_id,data,lat,lng,status,zoom) VALUES('1494','','','','0','0') It's getting the zeros correct for status and zoom, which are integer fields. So, the way around it is to set those subfields to zero before saving. So, this works: $basic_page = $templates->get("basic-page"); $wp = new Page(); $wp->parent = $pages->get("/about/"); $wp->template = $basic_page; $wp->title = 'testme'; foreach($wp->fields as $pf){ if($pf->type=="FieldtypeMapMarker"){ $wp->$pf->lat = 0; $wp->$pf->lng = 0; } } $wp->save(); But I want to come up with a solution that will allow creating a page with any custom field that might use float sub fields. I even thought about setting the values of all fields and subfields to 0 before (to be overidden later), but can't even do that because it seems impossible to find out the subfield names until a page is created with that template - am I missing something obvious here? Then again, I feel like this is PW should handle properly in the core. I am not even sure I know why it is trying to set the values of fields on page save if they weren't specified anywhere. Any thoughts? EDIT: I am beginning to think this is actually an issue in general with MapMarker as I can't create new pages in the admin either - I'll investigate further. Edited March 14, 2014 by adrian Link to comment Share on other sites More sharing options...
Wanze Posted March 14, 2014 Share Posted March 14, 2014 I think it should work if you initialize the values with zero here: https://github.com/ryancramerdesign/FieldtypeMapMarker/blob/master/MapMarker.php#L33 2 Link to comment Share on other sites More sharing options...
adrian Posted March 14, 2014 Author Share Posted March 14, 2014 Hey Wanze, You're right for sure. I got thrown because I though it was just API related, but it actually seems like a bug between MapMarker and the latest version of PW. I looked back at a couple of sites that are working fine and MapMarker has always defined those as '' and not 0 and they have always been float fields. Not exactly sure what changed where, but this definitely fixes it. I'll submit a pull request for Ryan. Thank You!! 1 Link to comment Share on other sites More sharing options...
Wanze Posted March 14, 2014 Share Posted March 14, 2014 You're welcome. I think Ryan did some work on the float fields - there was a problem that float values were "cut down" to integers due to the local set by PHP, if multilang support was enabled. Maybe something changed how an empty value is handled too. Cheers 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now