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.

CommentFileSizeAuthor
#9 devel.patch814 bytesKarenS
#4 devel.patch3.2 KBKarenS
#3 devel.patch3.18 KBKarenS
#2 devel.patch3.31 KBKarenS
#2 cck.patch4.94 KBKarenS
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

I 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.

KarenS’s picture

FileSize
4.94 KB
3.31 KB

Well 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).

KarenS’s picture

FileSize
3.18 KB

Actually 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.

KarenS’s picture

Status: Active » Needs review
FileSize
3.2 KB

Well 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 :)

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Yeah, 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.

moshe weitzman’s picture

Status: Reviewed & tested by the community » Fixed

oops. 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.

KarenS’s picture

Looks 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!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

KarenS’s picture

Status: Closed (fixed) » Patch (to be ported)
FileSize
814 bytes

Here's a small patch to make this work in D5. I'm committing the matching code on the CCK side for this to work.

moshe weitzman’s picture

Status: Patch (to be ported) » Fixed

committed. thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.