4

Background: I'm writing a module that will hopefully make reverse-engineering specs for site audits easier. (If you're interested, you can see the Topograph module-in-progress on my Github account.)

Basically it's a bunch of byzantine views that use custom handlers to pull things like serialized data out of the DB to display stuff like nodetype settings to the admin user.

I'm having a lot of trouble finding certain things, though. Fieldset info is a major one, as well as settings like whether the field is required. I'm not finding it in the blob of data pulled from the {field_config_instance} table (though I might be overlooking it). Can someone point me to where this info can be retrieved per nodetype/field instance?

7
  • i think field_config_instance for example only has like the required setting, if the parent field element options are altered in any way for a bundle (because fields can exist in many bundles) ... so i'm not sure you can rely on looking at 1 SQL table. thats why field_get_info() exists.
    – tenken
    Commented Aug 21, 2013 at 23:12
  • That function doesn't seem to exist, and the closest thing I could find, field_info_field(), doesn't seem to have fieldset or required info in the return value.
    – beth
    Commented Aug 21, 2013 at 23:23
  • Does it have to be DB, or can you do it via the API?
    – mpdonadio
    Commented Aug 21, 2013 at 23:25
  • Via the API works fine too.
    – beth
    Commented Aug 21, 2013 at 23:25
  • field_info_instance() should do it, the 'required' setting is under 'settings' in that array. By fieldset info do you mean the stuff field_group provides? If so that's in the field_group table. If you're looking at the db structure in a GUI it's easy to miss the field_group table, it gets buried in amongst the field data/revision tables
    – Clive
    Commented Aug 21, 2013 at 23:33

1 Answer 1

2

Whether a field is required or not can vary by content type (ie, the bundle). I am pretty sure you need to use field_info_instances($entity_type, $bundle_name). You can then use field_info_field($field_name) on the results. Something like:

$fields_info = field_info_instances('node', $bundle);

foreach ($fields_info as $field_name => $instance) {
  $field_info = field_info_field($field_name);
}

dpm() both the $instance and $field_info. Everything you need should be in those two variables. This is a snippet from a dynamic exporter I have.

4
  • I will note as a comment, that I am not positive that the fieldset info is in there.
    – mpdonadio
    Commented Aug 21, 2013 at 23:35
  • 1
    Fields don't have any related fieldset info as such, some modules (e.g. field_group) provide them but they're stored separately (in a table and as ctools exportables)
    – Clive
    Commented Aug 21, 2013 at 23:38
  • That makes sense. I hardly every use groups.
    – mpdonadio
    Commented Aug 21, 2013 at 23:43
  • 1
    Neither fieldset nor required info is provided by field_info_instances() or field_info_field(). Clive, if you can tell me where field_group stores fieldset info, please do. I can't find it.
    – beth
    Commented Aug 21, 2013 at 23:46

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.