vdchristelle
10/8/2013 - 7:40 AM

Default image not available in tpl files

Default image not available in tpl files

/**
 * DECLARING THE BLOCK
 * Implements hook_block_info().
 */
function the_aim_team_block_info() {
  $blocks['teamblock'] = array(
    // The name that will appear in the block list.
    'info' => t('the AIM team members'),
    // Default setting.
    'cache' => DRUPAL_CACHE_PER_ROLE,
  );
  return $blocks;
}

/**
 * RETRIEVING DATA FROM DB
 * Custom content function. 
 * 
 * Implements hook_contents().
 * 
 * @return 
 *   array of the targeted slide nodes
 */
function the_aim_team_contents(){
  global $language;

  //Get slide nids
  $nids = db_select('node', 'n') //table, alias
          ->condition('type', 'team_member') //content type
          //->condition('language', $language->language)  //language
          ->condition('status', 1) //Published.
          ->fields('n',array('nid'))  //SELECT the fields
          ->orderBy('created', 'DESC') //ORDER BY created most recent
          ->execute()
          ->fetchCol();

  //get node content from cache
  $nodes = array();
  if(count($nids) > 0) {
    $nodes = node_load_multiple($nids);
  }

  //we must add the default picture to the image
  //node_lode does not get that value
  $field = field_info_fields();
  $uri = file_load($field['field_afbeelding_team']['settings']['default_image'])->uri;
  $filename = file_load($field['field_afbeelding_team']['settings']['default_image'])->filename;
  
  //no image uploaded ? replace by default image
  foreach($nodes as $key => $node){
    if(count($node->field_afbeelding_team) == 0){
      //$node->field_afbeelding_team['und'][0]['filename'] = $filename;
      $node->field_afbeelding_team['und'][0]['uri'] = $uri;
    }
  }

  return $nodes;
}