I have an AJAX form that replaces a section of itself successfully when the user is logged in. But when logged out, the demo-area section comes back with the #prefix and #suffix but no item-header or item-display. $files is an array of my objects that create the custom-themed sections successfully. I can't figure out what is causing them to return empty in AJAX when logged out.
I think permissions are fine. When logged in, the initial form load and AJAX replacements work as intended. When logged out, the demo-area loads correctly with the page, but is then replaced with only #prefix/#suffix on AJAX calls.
Here is the part of my form builder function in question:
$files = array();
foreach ($node->field_file[$node->language] as $field_file) {
$files[] = new ClientDemoItem($field_file);
}
$form['file-index'] = array(
'#type' => 'select',
'#options' => array_keys($files),
'#default_value' => 0,
'#ajax' => array(
'callback' => 'client_demo_load_item',
'wrapper' => 'client-demo-area',
),
);
$file_index = isset($form_state['values']['file-index'])? $form_state['values']['file-index'] : 0;
$form['demo-area'] = array(
'#prefix' => '<div id="client-demo-area">',
'item-header' => $files[$file_index]->buildHeader(),
'item-display' => $files[$file_index]->buildDisplay(),
'#suffix' => '</div>',
);
Here is the simple AJAX callback:
/*
* Replace the demo area with the requested file display
*/
function client_demo_load_item($form, $form_state) {
return $form['demo-area'];
}
Here is what the buildHeader() function does:
public function buildheader() {
$item = array(
'#theme' => 'client_demo_item_header',
'#url' => file_create_url($this->uri),
'#description' => $this->description,
'#filename' => $this->filename,
'#filesize' => filesize($path),
'#timestamp' => $this->timestamp,
'#fid' => $this->fid,
'#item_file' => $this,
);
return $item;
}
$files
array is empty during the ajax request but can't tell without more information.