0

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

1
  • 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?
    – avpaderno
    Commented Dec 26, 2012 at 7:32

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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