I would love to see an example of how a module can add a field (using the term loosely) to the "Manage fields" and "Manage display" pages so that the user can order the field's position in the display without needing to monkey with their theme.
My module takes information from the admin and constructs the display. Currently (D6) it requires a node.tpl.php change. I want to eliminate that.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | rfay_dell_Selection_081.png | 35.09 KB | rfay |
| #1 | rfay_dell_Selection_080.png | 16.67 KB | rfay |
Comments
Comment #1
rfayHmm.. The "manage display" page has javascripty ordering capabilities... You may be talking about more than ordering, but that's definitely in theme-land. But if you're talking about ordering, D7 has it all covered. D6 does too, if I remember. However, in Examples we cover only core examples, so don't cover CCK.
So if I understand your question right, D7 does it all out of the box. And Field example explains how to make a custom field.
Here's the "Manage Display" page
Comment #2
RKS commentedI think what she's asking is how a module can automatically add the fields instead of user adds fields. It is easy and intuitive for users to add fields in D7, just like your example, but I think she's asking to eliminate the need for the user to do that.
As for the support aspect of not covering contrib modules here, this probably be would outside the scope of this area.
Comment #3
rfayCommerce has lots of examples of adding fields programmatically.
But the Node Example here does it. It creates a node type and then adds fields to it.
See below:

Comment #4
nancydruFirst, this is for a D7 version of the User Badges module. I don't expect to back-port this feature to D6.
There is already a UI for creating badges and adding them to users. This is not really a field. It's more like the "submitted by" or links stuff where the module consolidates data from elsewhere to build the content of the "field."
Currently, our instructions are to alter node.tpl.php to place the badge images. I have a hook_preprocess_node to make that slightly easier in D7, but I really dislike requiring theme changes. It would be so much nicer if it could be handled in the Fields UI (i.e. CCK).
I looked at how Pathauto adds its field to "Manage fields" and have gotten that one to show up, but I'm not convinced that it matters as the badge UI is not part of the node building. But no luck so far on following the APIs to add it to "Manage Display" where it can actually be manipulated for display.
Comment #5
rfaySo you're talking about adding to "manage display" something which is *not* a field, then? I just looked and the nodeapi_example, which does something like what you're talking about (adding a rating element to a node type) also fails to get the rating into the "manage display".
I think the most likely technique would be to go with a field...
Comment #6
nancydruIs that how Taxonomy adds the rolled up terms? Does one of the example modules give a clear explanation of this process?
Comment #7
rfayTaxonomy terms are now fields. So yes... the node example and the field example.
Comment #8
nancydruI don't find those examples to be terribly helpful for my case. Taxonomy is fairly close, except there is no interaction with a bundle (like a node). Well, actually, badges belong to the user, so maybe I should look at extending the user object, but that would be the subject of a second version for 7.x. A more-or-less straight port from 6.x would be better for the first version; so maybe I will postpone this and come back to it later.
Comment #9
RKS commentedCould you possibly use a dependency on the module Viewfield whereas your field is actually a view and the view is gathering your badges as images? So if a user has a badge it is grabbed by the viewfield and if not then the field is not displayed.
On a sidenote, I was about to start a D7 site where it would be heavily reliant on user badges in a social type setting (like GetGlue) so I'm glad you mentioned this, Nancy. I haven't even started looking into the available user badge modules so good to know they aren't up yet. I can help with this module if you would like since I will be needing it myself shortly. Just let me know.
Comment #10
nancydruIt's not a view, in the sense of being provided by the Views module, which is what Viewfield is for. I use the word in the generic sense, or partially because I was looking at trying to make hook_view work.
There is a new module (I think Achievements), which is a fork of User_Badges. I think my newest code (which I have as yet to upload) is very close to good, as long as you don't use the user role badge feature. But I could always use more help, especially if you know Git (I don't yet). Well, duh, I just looked at your real name... You've got my email address.
Comment #11
pebbl commentedIf I've understood what you are requesting correctly, the hook you are looking for in D7 is hook_field_extra_fields:
An example of this would be:
You can then use the following to render what your fake field does:
For inspiration and examples look to the eva module, I was rather overly happy when I found this -- my task went from something near impossible, to very simple. Thank you D7 :)
Comment #12
mile23Entity Example shows how to implement hook_field_extra_fields(): http://api.drupal.org/api/examples/entity_example%21entity_example.modul...
Node Example shows how to add fields programmatically, in node_example_node_type_insert(). I'd link to it, but the api.d.o site hasn't crawled it yet.
Marking this as closed but please re-open if we're missing something.