Provide a way for developers to get a hierarchy of fields in the same order they'd be rendered on a node edit form.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | fieldtool.module-696270-field_hierarchies.patch | 2.96 KB | Matthew Davidson |
| #3 | fieldtool.module-696270-field_hierarchies.patch | 2.53 KB | Matthew Davidson |
| #3 | fieldgroup.inc_.txt | 1.63 KB | Matthew Davidson |
Comments
Comment #1
Matthew Davidson commentedfieldgroup_groups() provides this pretty well by itself. However not just fieldgroup, but other modules provide fields in hierarchies. eg. A Link field can be seen as a fieldgroup with URL, Title, etc. Maybe we need a new hook so that all these modules can return information about how the "flattened" field names fit into the overall field hierarchy.
Comment #2
Matthew Davidson commentedThink the way to deal with this is to introduce the concept of "grouping fields". Any field can be a parent of other fields. We'll need a new hook so that plugins can declare which fields are children of a field. Also need a new function like fieldtool_get_tree($content_type, $depth) which would give us the same sort of structure you'd get from the node edit form.
Probably also best to establish conventions for field names. For anything other than standard fields for an entity (handled by node_standard.inc, user_standard.inc, etc.) the convention should be module_name_field_name_subfield_name_sub-subfield_name (CCK/D7 fields are already prefixed with 'field_' so we'll stick to that). This should hopefully deal with namespace collisions.
To illustrate, in the case of fieldtool_fields() might return something like:
... and fieldtool_get_tree() might return something like:
So here you can still just pass the import callback of 'field_link' a string and it will assume it's a URL and pass it on to the import callback of 'field_link_url'. CCK Fieldgroup fields would be just like any other fields, only without getter/setter/import/export callbacks.
Comment #3
Matthew Davidson commentedDidn't require a new hook at all. Plugin developers just have to add an array of child field names to the array returned by hook_[plugin]_fieldtool_fields(). This doesn't affect existing functionality at all, just adds a new fieldtool_tree() function which returns an array as suggested above.
Seems to work with the attached fieldgroup plugin. Will commit both when I've modified relevant existing plugins (location, link, taxonomy, etc.) to work like this. In the meantime testing appreciated.
Comment #4
Matthew Davidson commentedWhoops, should have changed status.
Comment #5
Matthew Davidson commentedFixed another glitch where function fieldtool_export() wanted a $value argument. Copy and paste error by the looks of it; fieldtool_import() has that argument in the same place. I know it's bad form not to raise a separate issue, but let's be honest - who's reading this, anyway?
Will create separate issues for support for this in various plugins. Wanted this committed, as I've now got support for this in the taxonomy plugin I'm about to commit (#649848: Support taxonomy (not content_taxonomy) fields).