On every creation of a node or edit of a node I need the "Authored by" field to be automatically populated with the username of anyone saving changes.
any ideas how I can do that?
Thanks.
欢迎各位兄弟 发布技术文章
这里的技术是共享的
3 | On every creation of a node or edit of a node I need the "Authored by" field to be automatically populated with the username of anyone saving changes. any ideas how I can do that? Thanks. | ||||||||||||||||
|
4 | Personally I think that a module like Rules (powerful and awesome as it is) is overkill for something relatively simple as this. Looking at node_form(), I see that the author is set by populating the author field with the username. I would create a custom module which implementshook_form_BASE_FORM_ID_alter, and set the default value of the author name field to the name of the current user. That would look something like this (disclaimer: untested code!).
An advantage of this solution is that the field is populated in advance with a default value, allowing user with sufficient permissions (eg. administrators) to override the author as they always can. It would be harder to do that in a rules-based approach which only kicks in after the form has been submitted. update: The topic starter mentions in another answer that he ended up with the following code:
Some feedback on this code:
| |||
3 | I'd use Rules to do this. You need to create a rule to respond to a node being updated, then add an action which sets the author value from the current user. | ||
0 | thanks a bunch, It worked well and I simply did this(just a few changes from what you've written)
| ||
-1 | This should just happen when created, if Author and Date information are ticked in admin/structure/types/manage/[your_content_type], under display settings. If you want something else, you can use the token module and use a token as default value ; again in the content type settings. If you want it updated with every save, you have to use hook_node_update() in a custom module, and set | ||||||||
|