Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
 
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 Aug 21 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 Aug 21 at 23:23
 
Does it have to be DB, or can you do it via the API? –  MPD Aug 21 at 23:25
 
Via the API works fine too. –  beth Aug 21 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 Aug 21 at 23:33
show 2 more comments

1 Answer

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.

share|improve this answer
 
I will note as a comment, that I am not positive that the fieldset info is in there. –  MPD Aug 21 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 Aug 21 at 23:38
 
That makes sense. I hardly every use groups. –  MPD Aug 21 at 23:43
 
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 Aug 21 at 23:46

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.