I am trying to print the filefield description. I have tried several things and can't seem to get it.
I have a simple file upload content type. It's machine name is share_files. The only field is the filefield and I have the description turned on. It is named "field_sfile."
The best that I have come up with is print $content->field_sfile['description']['0']['value'];
I am not really a coder, but I am trying to learn. My ultimate goal is a small module that will use the description field to create the title. I want to use auto nodetitle to help with this, but there is no token for the filefield description.
Below is the relevant information from adding print_r(array_keys($content)); to the body of an overridden template file for this content type.
["field_sfile"]=>
array(16) {
["#theme"]=>
string(5) "field"
["#weight"]=>
string(1) "1"
["#title"]=>
string(12) "Shared Files"
["#access"]=>
bool(true)
["#label_display"]=>
string(5) "above"
["#view_mode"]=>
string(4) "full"
["#language"]=>
string(3) "und"
["#field_name"]=>
string(11) "field_sfile"
["#field_type"]=>
string(4) "file"
["#field_translatable"]=>
string(1) "0"
["#entity_type"]=>
string(4) "node"
["#bundle"]=>
string(11) "share_files"
["#object"]=>
object(stdClass)#88 (29) {
["vid"]=>
string(2) "66"
["uid"]=>
string(1) "1"
["title"]=>
string(22) "[node:menu-link:title]"
["log"]=>
string(0) ""
["status"]=>
string(1) "1"
["comment"]=>
string(1) "1"
["promote"]=>
string(1) "1"
["sticky"]=>
string(1) "0"
["nid"]=>
string(2) "66"
["type"]=>
string(11) "share_files"
["language"]=>
string(3) "und"
["created"]=>
string(10) "1316383429"
["changed"]=>
string(10) "1316446540"
["tnid"]=>
string(1) "0"
["translate"]=>
string(1) "0"
["revision_timestamp"]=>
string(10) "1316446540"
["revision_uid"]=>
string(1) "1"
["field_sfile"]=>
array(1) {
["und"]=>
array(1) {
[0]=>
array(12) {
["fid"]=>
string(2) "85"
["display"]=>
string(1) "1"
["description"]=>
string(28) "June 2011 New Blu-ray Movies"
["uid"]=>
string(1) "1"
["filename"]=>
string(18) "jun_11_blu-ray.pdf"
["uri"]=>
string(40) "public://shared_files/jun_11_blu-ray.pdf"
["filemime"]=>
string(15) "application/pdf"
["filesize"]=>
string(6) "190898"
["status"]=>
string(1) "1"
["timestamp"]=>
string(10) "1316446540"
["origname"]=>
string(18) "jun_11_blu-ray.pdf"
["rdf_mapping"]=>
array(0) {
}
Comments
This prints the link to the
This prints the link to the file upload with the file name as added by the description and the label.
print render($content['field_sfile']);
All I want is the description. I thought I could write something like below.
print render($content['field_sfile']['description']);
It just does not work.
Solved I figured out some of
Solved
I figured out some of what I was doing wrong and elaborated on the original tries, but for some reason I could never figure out how to get down into the #object array which contained the first instance of the description that was trying to get. I would get an error that began with "Cannot use object of type stdClass as array." But if you scroll down to the *RECURSION notation, I was able to print render the description through the #item array with the following code.
print render($content['field_sfile']['#items'][0]['description']);
I am just learning some of this, so an experienced developer may be able to elaborate or correct any of my vocabulary.
Here is the print_r of ($content['field_sfile']); for reference to see how I tracked down the data that I was trying to print out. I hope this helps someone.