Greetings!

I need to set the default value of a location form item via a link from another node.

Example:
A coordinate is saved in node/16. When viewing node, by clicking link 'add note to this location', the content type
'note' input form is loaded, containing coordinates inherited from node/16.

Any clue how I can do this? :)

Thanks

Comments

farald’s picture

Title: Set location in create-new-node-form from another node » node/add/nodetype: Default lat/lon-values by modifying $form

This is easily applied to other fields by modifying the default values of the node/add/nodetype $form.

But where in the $form array are the default values for the locations?

I have tried multiple solutions, but none seems to work. Some even changes the default value -> in the array,
but still, the node form are not showing the inserted new values from the array.

Now Im stuck.

farald’s picture

Component: Documentation » Code
yesct’s picture

is this where form_alter could be used?

There are some other posts in the location issue queue about form_alter

Maybe they could help you?
http://drupal.org/project/issues/search/location?text=form_alter&assigne...

yesct’s picture

farald’s picture

Status: Active » Fixed

Ive found a a solution to this (a hack, but still). For reference:
#143289: Pre-populate node location from author/organic group etc. comment no #7.
This hack enables locations to be set at user's location.

I need to be able to create nodes with lat/lon inherited from previous node.
If no node to inherit from, the location needs to be set at the user's location (users only post nodes to their immediate area)

The easiest way is to check for a node id in arg(3) after node/add/nodetype/ to inherit from.
So i replaced ron_s's first part with this:

<?php
	if (!is_numeric(arg(3))){
		global $user;  
  		$user_location = location_load_locations($user->uid, 'uid'); 
  	} elseif (is_numeric(arg(3))) {
  		$user_location = location_load_locations(arg(3), 'nid');
  	};
?>

Then I used the last part as it was.

yesct’s picture

Status: Fixed » Needs work
Issue tags: +location useful code

changing this to code needs work. Maybe someone can take what you started and use it to write a patch for location to get this in officially? :) If this sits here for a while with no-one running with what you started, I might mark it postponed.

and tagging with useful code.

yesct’s picture

Status: Needs work » Postponed
rooby’s picture

Status: Postponed » Fixed

Location form elements cannot be modified using hook_form_alter().

Instead use hook_locationapi() that the location module provides.

For an example of setting default values see #367218: How to force a default on Location Name and disable/protect form input

Status: Fixed » Closed (fixed)
Issue tags: -location theme edit form, -Location theming, -location auto-complete, -location useful code

Automatically closed -- issue fixed for 2 weeks with no activity.