I'm kind of new to Drupal development and I'm a little lost on something I'm trying to do:
My company has several locations and I am developing a method whereby each location can have their own page on my company's website.
I want location managers to be able to log in and post news articles about their respective locations and have those articles appear on the appropriate location page.
I have content types set up for 'Location' and 'Site Articles'. 'Site Articles' has a 'Location' field that is a reference type back to Location.
In an effort to restrict the ability of various site managers to select a location that is not theirs, I am using hook_form_alter() to adjust the 'Location' entity reference in the 'Site Article' content type that reads what Site a manager belongs to in their User Account Settings, and adjusts the form so that ONLY the managers site shows up. That code looks like this:
function smg_site_articles_form_alter(&$form, &$form_state){
global $user;
$account = user_load($user->uid);
if(!empty($form['field_site_news_article_location'])){
$entity_node = node_load($account->field_user_location['und'][0]['target_id']);
$form['field_site_news_article_location'] = array(
'#title' => 'location',
'#type' => 'select',
'#options' => array(
0 => t($entity_node->title)
),
'#default_value' => $entity_node->title);
The problem that I'm running into is when I save the Article, the "Location" entity reference does not get populated and I can't add Views filters to it the way that I want.
I'm assuming the problem lies with how I'm altering the 'Location' entity refernce field in hook_form_alter(), but I'm a little lost as to how I get the data updated correctly.
Can anyone help??