How to set the Organic Group while saving a node based on the node's current language We want to use a hook_node_presave to set the Organic Group (OG) field on the basic page content type based on the node's language. We have created several OGs using nodes and each one is assigned a language so there is a mapping between Language to OG based on the OG node.  

So basically, when the basic pages' language is set to en, then the OG with a language of en, will be assigned to the basic page's OG field. 

Current nodes:

OG1 
--Title = test 1
--language = en

OG2
--Title = test 2
--language = en-gb

OG3
--Title = test 3
--language = fr

basic page1
--title = some title1
--language = en
--og_field = ??

basic page2
--title = some title2
--language = fr
--og_field = ??



Expected result when the hook_node_presave is done:

basic page1
--title = some title1
--language = en
--og_field = OG1

basic page2
--title = some title2
--language = fr
--og_field = OG3



here is what i have tried, but not sure why it is not working (assume organic_group is the content type machine name)

function mymodule_node_presave(&amp;$node) {

    if($node-&gt;type == 'page') {
        //get the OG node that has the same language as the current node
        $result = db_select('node', 'n')
           -&gt;fields('n', array('nid', 'language', 'og_field'))
           -&gt;condition('n.type', 'organic_group')
           -&gt;condition('n.language', $node-&gt;language)
           -&gt;execute()
           -&gt;fetchAll();

        //store OG node's nid into og_field
        $node-&gt;og_field = $result-&gt;nid; 
    }
  }
Using Rules, you can add an event for when a new node is saved, add conditions for both content type and language and then use an action for assigning the OG's nid to the og_group_ref field.

Use set a data value if cardinality of the node is set to 1 or add to list for more than 1.

Without rules or code, I would have a new node link in each organic group and prepopulate the language and og_group_ref fields.