i've a custom filefield in a custom content type and i use to display it in a node.tpl .But here my filefield has no limit number and under D6 i use this code :
foreach($node->field_objectif_bts as $file) {
if ($file['view']) {
$header = array('data' => 'Les objectifs des formations BTS');
$rows[] = array($file['view']);
$attributes = array('id'=> 'objectif-bts','sticky' => FALSE);
}
}
$output = theme('table', $header,$rows, $attributes);
print $output;
In Drupal 7 it doesn't work, so I'm looking for modifications to do on this code or new code for Drupal 7 theming.
Actually, I tried the following.
foreach($node->field_objectif_bts as $file) {
if ($file['und']['value']) {
$header = array('data' => 'Les objectifs des formations BTS');
$rows = array($file['und'][0]['value']);
$attributes = array('id'=> 'objectif-bts','sticky' => FALSE);
}
}
$output = theme('table', array('header' => $header, 'rows'=> $rows), $attributes);
print $output;
I also tried this code, but I get an error.
$w = entity_metadata_wrapper('node', $node);
foreach ($w->field_objectif_bts->getIterator() as $file_w) {
// $file_w->file returns the wrapper of the File entity. You can
// then address it's values as:
$name = $file_w->file->name->value();
$mime = $file_w->file->mime->value();
$custom_field = $file_w->file->field_objectif_bts->value();
// etc. You can see all available fields by inspecting the
// return value of $file_w->file->getPropertyInfo()
if ($custom_field) {
$header = array('data' => 'Les objectifs des formations BTS');
$rows = array($custom_field);
$attributes = array('id'=> 'objectif-bts','sticky' => FALSE);
}
$output = theme('table', array('header' => $header, 'rows'=> $rows), $attributes);
print $output;
}
The error is the following:
EntityMetadataWrapperException: Unknown data property field_objectif_bts. in EntityStructureWrapper->getPropertyInfo() (line 339 of /var/www/drupal7/sites/all/modules/entity/includes/entity.wrapper.inc).