Created
September 13, 2012 21:26
-
-
Save nucklearproject/3717801 to your computer and use it in GitHub Desktop.
Imprimir el valor de un field desde cualquier entidad de Drupal.-
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Usamos directamente la API de drupal. field_get_items() | |
Si antes hacias esto echo $node->field_subtitle['und'][0]['value']; | |
Aunque funciona olvidate de volver a hacerlo! | |
*/ | |
/* | |
Tomamos como referencia un field creado en la entidad user. | |
*/ | |
$user = user_load(1); | |
$any_field = field_get_items('user', $user, 'field_any_field'); | |
var_dump($any_field); | |
echo $any_field[0]["value"]; | |
/* Llamando a un field desde un node */ | |
$node = node_load($node->nid); | |
$any_field = field_get_items('node', $node, 'field_subtitle'); | |
echo $any_field[0]["value"]; | |
/* | |
Otra opción es usar el modulo entity http://drupal.org/project/entity | |
*/ | |
$user = user_load(1); | |
$entity_user = entity_metadata_wrapper('user', $user); | |
$any_field = $entidadUsuario->field_any_field->value(); | |
echo $any_field; | |
/* | |
Mas referencias acá: http://www.e-capy.com/drupal-7-obtener-el-valor-del-field-de-una-entidad/ | |
acá: http://pixeljets.com/blog/writing-robust-code-uses-fields-drupal-7 | |
y acá : http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way | |
y obviamente acá: https://www.google.com/search?q=$any_field+=+field_get_items#hl=es&gs_nf=1&tok=P9JlWcFkEtTolGTP4RZ2CA&pq=field_get_items&cp=17&gs_id=28&xhr=t&q=print+field+with+field_get_items&pf=p&sclient=psy-ab&oq=print+field+with+field_get_items&gs_l=&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.&fp=6a52e9c363ea895d&biw=1220&bih=748 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment