I propose a new field op which can be called by devel_generate module. This op would return some random dummy values that respect the allowed values for a given field. multiples should be provided if they are allowed.

devel_generate will attach the provided values to a node object and call node->save() to create new nodes.

In an ideal world, we get this working even for complex field types like imagefield.

CommentFileSizeAuthor
#4 mw.patch1.72 KBmoshe weitzman
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

As of today, devel_generate will create content for custom content types that have no cck fields attached. This issue is about removing this restriction. Would be very nice for getting a quick picture of how a site will look/feel/perform with real content.

moshe weitzman’s picture

I'd love some tips about how to implement this. I can probably code it if someone outlines the steps needed.

KarenS’s picture

Interesting idea, but I'm not sure I completely understand which fields you would implement. Are you assuming the admin will have already created some fields and devel will just populate them, or that we would create dummy fields out of whatever CCK fields are enabled and then populate them with dummy values?

And what exactly would you want returned? An array of populated field arrays for that content type, or a node object with the fields attached, or what?

moshe weitzman’s picture

Assigned: Unassigned » moshe weitzman
Status: Active » Needs work
FileSize
1.72 KB

Yes, i am assuming the admin has already setup his fields as desired. we are only generating nodes - not generating content types.

Please see the changes i've made to in this patch to text.module in HEAD. this is my general idea. this works with the very latest devel_generate module in devel package. the function that calls the new text.module code is devel_generate_fields() at bottom of devel_generate.inc

By increasing complexity of devel_generate_fields(), i could simplify the generate field op so it doesn't have to care about multiple handling. worthwhile?

Comments welcome. Once I get some positive feedback, I'll implement a few more types and possibly backport to 5. Not sure yet how easy that is.

KarenS’s picture

Just looking at this, not actually trying it out, I think this is an interesting and useful idea.

The code to identify the number to use for $max and the selection of allowed values, if there are any, is going to be the same for all fields that let the content module handle multiples, so maybe we could simplify this by putting this code into the content module's default field instead of each individual field, and have the default field invoke the individual fields to get a dummy value to insert as needed into the field array. Like we're doing now with widgets, maybe change it so the field module just responds by creating a single valid random dummy value when invoked and let either the content module or devel combine them into a full field.

The only other issue, especially if we simplify this by having devel or content combine the values, is that we have to think about the more complex fields that handle things differently and be sure we have a method where they can opt out of our simplified handling to provide their own values.

KarenS’s picture

OK, here's one theoretical way to do it:

1) Put the code in your patch into the content module's default field instead of the text field.

2) Where you get to the place in the code where you need a random value that is not coming from the allowed values list, invoke a hook_content_generate($field) to get a random valid value. Add that hook into the individual field modules instead of having them use the 'generate' op.

3) That means that modules letting the content module handle this will *not* have a 'generate' op, Fields that want to do their own handling can create their own 'generate' op to do something different.

4) The content module default field gets called after the individual fields, so it should detect if a value has already been provided by the field and do nothing in that case, otherwise provide the value.

moshe weitzman’s picture

I pondered this proposal a bit and don't think I like it. The main problem is that we don't want a default implementation for modules that don't implement this hook. For example, consider funky fields like 'address'. If we provide a default text string for it, then its goig to freak out or even worse, it will save our data and the generated node is hopelessly corrupted. It is better to have empty values for fields that don't generate this hook.

I do like moving the generate implementation to its own hook, since that lets any module provide the implementation if the module author is unwilling or unavailable. I'll do that for text module and enhance devel_generate_fields() so it calls multiple times for multi-value fields (if content module handles multiples).

KarenS’s picture

I can see your point, and it's probably cleaner to do the work in devel anyway, so that sounds good to me. I would just keep in mind that it is possible that some field modules will want to create their own, different, method of generating dummy content and allow for some way they can do that.

moshe weitzman’s picture

i have been pulled off of this for now. i think i will implement it in devel_generate exclusively until i am ready to show here. help wanted.

clemens.tolboom’s picture

I ran into troubles too with http://drupal.org/project/node_factory when creating cck nodes on the fly through i.e. workflow_ng.

flickerfly’s picture

sub

KarenS’s picture

Status: Needs work » Patch (to be ported)

There is a patch for this in the Devel module node and I've added code to the 6.x version of CCK that will work if that patch or something else similar to what is discussed there gets committed. I'm marking it 'to be ported' to keep it open until we see what happens in devel and in case the devel module wants to port that capability back to 5.x.

KarenS’s picture

Status: Patch (to be ported) » Fixed

Moshe committed the Devel end of this and I made some more changes and committed them here, so at this point this should work to generate random content for text, number, nodereference userreference, and date modules. Other modules can follow the examples to add support for this feature. The code for everything but the Date module is in the new content.devel.inc file in the CCK includes folder.

Not sure whether or not this will get back ported, so I'll mark it fixed for now.

moshe weitzman’s picture

If anyone makes a patch for 5.x version of devel_generate, i'll commit it.

Thanks KarenS

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

chrism2671’s picture

Status: Closed (fixed) » Active

This is a good + necessary idea. Fields should be autopopulated using the devel module, but if, for example, it's an email field, well the field needs to have something that will pass the validation. That should be handled by the field and not by devel - consequently this is quite a good addition. It's not much work either for field developers.

KarenS’s picture

Status: Active » Fixed

Why are you re-opening this issue? This is already done and committed and is a part of the code.

Fields can decide whether or not they want to provide dummy content and decide for themselves what content to provide by implementing hook_content_generate(). The content module iterates through all the node's fields and invokes the hook and sends that data back to the devel module. The devel module does not decide what content to create, it just inserts the values provided by the content module.

The hook is implemented by the core CCK fields in the file content.devel.inc and that code can be used as an example for any other field modules that want to do this. The field modules that implement the hook are obviously responsible for creating valid values.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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