When Weblinks nodes are created programatically via Devel Generate the url field is left empty. This not only causes an error message to be displayed for every node which is created, but it also means that the nodes cannot be editted and saved without having to manually enter a valid url value.

With a couple of lines in weblinks_node_presave() we can check if the node is being created via Devel Generate and then fill in a random (but valid) url. This will save tedious time that is currently wasted when doing testing.

Comments

jonathan1055’s picture

Status: Active » Needs review
StatusFileSize
new627 bytes

Here's the patch

nancydru’s picture

Devel has a hook for correctly generating extra fields in a node.

GStegemann’s picture

I have tested the patch and it works for me.

As Nancy mentioned we should use the devel hook to populate the url field.

jonathan1055’s picture

OK. I've done some searching and found in file devel_generate.fields.inc the function devel_generate_fields which looks like it should be the one you are talking about. However, on running debug in this, the field 'url' is not returned in the field instances. For the weblinks node type we only get taxonomy_weblinks and body.

function devel_generate_fields(&$object, $obj_type, $bundle) {
  dd('-- devel_generate_fields --');
  dd($object, '$object');
  //dd($obj_type, '$obj_type'); // 'node'
  dd($bundle, '$bundle');
  $field_types = field_info_field_types();
  //dd($field_types, '$field_types');
  $instances = field_info_instances($obj_type, $bundle); // url is not here.
...

Later in this function we would execute module_load_include('inc', $module, "$module.devel_generate"); but only if we found a field defined by weblinks (which we don't)

In file devel_generate.inc, function devel_generate_content_add_node(&$results) there is a comment:

  // A flag to let hook_node_insert() implementations know that this is a
  // generated node.
  $node->devel_generate = $results;

which implies that we can use this to do things in our own hook_node_presave().

I suppose we should try to do it with the proper include file if possible, but I'm not sure that we can, as our 'url' is not a field as defined in real Drupal terminology, we store it ourselves in our own table. The various field_info functions are not aware of it, but maybe we can make them aware?

GStegemann’s picture

Thanks for your research.

Yes, 'url' is currently not a real D7 field. I think as soon it will be made aware to the field_info functions it will also be filled by devel generate.

jonathan1055’s picture

Yes, but as far as I know, making url a full field would involve quite a bit of rework in the Weblinks code. Is that actually on our plan of things to do for 7.x-1.0?

One option would be to use the patch as supplied, but I will also add a note referring to this thread and saying to re-write with the specific devel_generate hook if/when we change the url to a real field. That way, we get the benefit now of a properly populated url for our testing, but we do not lose sight of the fact that there is another way to do it.

GStegemann’s picture

No, for 7.x-1.0 we should not make url as a full field.

I would opt for your option to use the patch as supplied and adding a note as you have described.

jonathan1055’s picture

StatusFileSize
new834 bytes

There is a nice discussion on whether to convert url to a field in #1197770: Roadmap reminder
Here is a patch with the extra comments.

GStegemann’s picture

Status: Needs review » Reviewed & tested by the community

Yes, I remember. But at that point in time I didn't know very much about all the impacts such a decision would have.

Comments are OK.

  • jonathan1055 committed b4a05cc on 7.x-1.x
    Issue #2414531 by jonathan1055: Populate url field for nodes created...
jonathan1055’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for testing.

Status: Fixed » Closed (fixed)

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

jonathan1055’s picture

Version: 7.x-1.x-dev » 6.x-2.x-dev
Status: Closed (fixed) » Needs review
StatusFileSize
new825 bytes

The same functionality is useful in 6.x too. Anything that saves us time and effort when testing/debugging is worth porting back.

The code addition is identical, but it goes in weblinks_nodeapi op=presave, instead of weblinks_node_presave.

GStegemann’s picture

Status: Needs review » Reviewed & tested by the community

The same functionality is useful in 6.x too. Anything that saves us time and effort when testing/debugging is worth porting back.

Yes, sure.

Tested and works. Thank you.

  • jonathan1055 committed 573252a on 6.x-2.x
    Issue #2414531 by jonathan1055: Populate url field for nodes created...
jonathan1055’s picture

Status: Reviewed & tested by the community » Fixed

Great! Thanks for testing.

Status: Fixed » Needs work

The last submitted patch, 13: 2414531_13.url_during_devel_generate.d6.patch, failed testing.

jonathan1055’s picture

Status: Needs work » Fixed

The issue is fixed. Old patch from #13 got requeued, and obviously it fails to apply because the code change is already committed in #15.

Status: Fixed » Closed (fixed)

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