Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

First, it's LANGUAGE_NONE not 'und'. Second, while I could go on how you should use field_get_items instead, it's very very likely you are missing some concepts here an you want a formatter, a whole display mode etc. You very rarely need that level of plumbing.


The constant LANGUAGE_NONE represents the value 'und'. Yes, using the value directly rather than the constant is bad practice, and certainly is not idiomatic in any language; I'll concede that point to you.

Regarding the use of field_get_items, check the documentation on the return value: "An array of field items keyed by delta if available, FALSE otherwise." Per my requirement of getting a single, OPTIONAL field value, field_get_items might return false, which means we are still looking at something like this overly verbose code:

($first_name = field_get_items('node', $person, 'first_name')) ? array_shift($first_name) : '';

Lastly, "you want a formatter, a whole display mode, etc. You very rarely need that level of plumbing". One of the requirements for this project was that each page represented by a person node would have a very specific layout. This meant that I couldn't rely on Drupal's default layout (even with formatters there was too much baked-in HTML that was unacceptable), and had to create a node--person.tpl.php file, i.e. a custom template.


I still say this: If your node.tpl.php contains field_get_items or equivalent, you are doing it wrong, on a very fundamental level. If the formatters provide too much HTML, write your own, write a proper field.tpl.php etc.


So in order to "print $person->first_name;", you must first create formatters, display modes, and templates? Point goes to the one who's saying that it's overly complicated. Drupal makes it easy to do difficult things, but infuriatingly difficult to do simple things.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: