Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I want to access the values of my field inside hook_block_view().

I tried with field_get_items(), and field_view_field() with no luck.

By the way the block is showing in a page. Is there a way to get the values set in the content type field settings?

screenshot

share|improve this question
1  
May you show the code you are using? If you want to get the value of a field, field_get_items() is the right function. Which arguments did you pass to the function? –  kiamlaluno Dec 26 '12 at 7:32

1 Answer 1

up vote 1 down vote accepted

You seem to need information about the field itself and not about its instances (neither globally nor in the context of a given entity).

Hence, you would want to do a:

$field = field_info_field('field_my_field');
$keys = array_keys($field['settings']['allowed_values']);
// $keys will now have the set of unique keys for your options as set from
// the field settings page. Eg. Alsace, Aquitaine etc.

field_my_field is the unique name of your field that you have also attached to a content type. To find this out, ensure the Field UI module is enabled, go to the Manage fields page for your content type and look up the Name column for the field in question.

If you are interested in knowing how the values you had set from the settings form go here, check out list_field_settings_form(). Here is a link to the documentation of field_info_field() as well.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.