0

When I create a new content type, I want to prefill a link field following this format :

/my/specific/link?node_id=<CURRENT_NODE_ID>

Is it possible to access the node id before his creation? Or a specific id to refer to this new content type??

[EDIT]

More details : I want to add a content type, which is a job offer. In this content type, there is a Link field, that refer to a web form to apply to the job offer. So I need to prefill the link field, with the node ID to know the job you are applying for.

0

1 Answer 1

1

You do not need a link field for that. You can generate link at theme level for example. Or even better in hook_node_view:

The module may add elements to $node->content prior to rendering. This hook will be called after hook_view(). The structure of $node->content is a renderable array as expected by drupal_render().

Last but not least, if you really want it to be a field, use Computed Field and have it calculated at save.

Computed Field is a very powerful field module that lets you add a custom "computed fields" to your content types. These computed fields are populated with values that you define via PHP code. You may draw on anything available to Drupal, including other fields, the current user, database tables, you name it.

2
  • Thanks a lot! I'm using computed field but it doesn't work (Display Code (PHP)): global $node; $display_output = l("Apply", "apply_form?job_offer=".$node->nid);
    – Bibix
    Commented Sep 24, 2013 at 10:36
  • @Bibix your comment above probably should be a separate question.
    – Mołot
    Commented Sep 24, 2013 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.