please help. I have tried so many ways to solve the following problem but did not succeed. I really need your support on this one.
Here is the problem: There are 2 content types : Fruits and Apple.
Apple content type has an entity reference field to fruits content type.
Now, whenever I view a node of type fruits, the entity reference field in apple add form should prepopulate to fruits node title.
Please see the image below. It will make everything clear.
Is it possible to prepopulate the field? If yes, how? Thanks.
The modules I am using right now: 1.Panels 2. Entity reference 3. Form Block 4. Entity reference prepopulate.
As per the suggestion from Sinan Erdem , I checked http://drupal.org/node/494008 . The code is below . It still doesn't work. :( Can you tell me why?
<?php
/** hook_form_alter **/
function pp_form_alter(&$form, $form_state, $form_id) {
// Check for a particular content type's node form. Form name is [content_type_name]_node_form
if ($form_id == 'apple_node_form') {
// Add an after_build function to process when everything's complete.
$form['#after_build'][] = 'pp_after_build';
}
}
/**
* Populate entity reference field
*/
function pp_after_build($form, &$form_state) {
// Obtain node object from nid in url
$entityreference_field_category = node_load(arg(1));
//populate autocomplete entityreference field with node title. Name of field is field_[field_name].
$form['field_category'][0]['nid']['nid']['#value'] = $entityreference_field_category->title;
return $form;
}
?>