Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is a followup to http://drupal.org/node/187599 to create a system for adding CCK field info to generated nodes. The summary of what Moshe wanted to do was have any field that wants to generate itself create a hook that will populate fields with random values. We will ignore fields that don't provide a hook rather than try to make a bad guess about what they would want, and third party modules can create hooks for fields that don't have one.
I need this now myself and need a solution for D6, but the same code should work in 5.x.
I'll post back here with an idea soon.
Comment | File | Size | Author |
---|---|---|---|
#9 | devel.patch | 814 bytes | KarenS |
#4 | devel.patch | 3.2 KB | KarenS |
#3 | devel.patch | 3.18 KB | KarenS |
#2 | devel.patch | 3.31 KB | KarenS |
#2 | cck.patch | 4.94 KB | KarenS |
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commentedI need to do same for OG Audience and other OG fields.
My thought was to simplify devel_generate's node creation function and have the modules like taxonomy, comment, cck, og, etc. work on hook_nodeapi('pre_save') to populate its fields. I would put a flag in like $node->devel_generate = TRUE so that modules know that it is time to populate their fields.
Comment #2
KarenS CreditAttribution: KarenS commentedWell I already rolled a patch and made the changes to CCK before seeing what you had posted here. I'll post what I have here and to CCK so you can see it. What's the advantage of using pre_save over a regular hook? We talked in the other issue about creating this in a way that another module can provide the hook if the field module does not. That seems more complicated if we use pre_save, but maybe it's not.
Anyway, here's what I had come up with which works fine (and I also have uncommitted code in the Date module to generate random dates using this method).
Comment #3
KarenS CreditAttribution: KarenS commentedActually this wouldn't be that hard to change after all. I just need to pull the devel_generate_fields() function into CCK and trigger it from the pre_save op. Then I can leave the hooks as hooks so other modules can supply code if the hook does not exist.
Attached is a patch. I left the current function in there as a wrapper so things will work until you make whatever changes you want to the devel module and I'm setting up CCK to work either from that function or from the pre_save op.
There is one other change in there -- adding a format argument to devel_create_content() so I can store both a value and a format for the textarea field.
Comment #4
KarenS CreditAttribution: KarenS commentedWell that was almost right, but I left out the content function, so here's another try.
And I went ahead and committed the complimentary code in CCK and in Date. I can tweak that code later to match whatever method you come up with, but I wanted to get the basic code to generate new field values committed before I lost all that work :)
Comment #5
moshe weitzman CreditAttribution: moshe weitzman commentedYeah, lets use a new hook as you've proposed. I've read through your patches, and I think they look swell. I just committed the devel patch to 6.x and HEAD.
Comment #6
moshe weitzman CreditAttribution: moshe weitzman commentedoops. i committed a patch before checking to see if you had made any updates. i've reverted and committed the latest. hope i got it right.
Comment #7
KarenS CreditAttribution: KarenS commentedLooks right to me. I found some more changes to make on the CCK side and then tested a number of different kinds of fields and it all seems to be working right.
Thanks!
Comment #8
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #9
KarenS CreditAttribution: KarenS commentedHere's a small patch to make this work in D5. I'm committing the matching code on the CCK side for this to work.
Comment #10
moshe weitzman CreditAttribution: moshe weitzman commentedcommitted. thanks.
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.