1

I'm desperately trying to programmatically add a new forum (in the 194 tid specific container) on node creation with rules.

I run php script when adding new node with rules, but I'm really newbee with php. I'm trying to use form_forum_form and form_forum_submit putting this variables :

require_once 'modules/forum/forum.admin.inc';

$autoform = array( 
     'name' => '[node:title]',
    'description' => 'Forum du projet [node:title]',
    'tid' => 194,
    'weight' => 0,
);


$form = forum_form_forum($form, &$form_state, $edit = $autoform);  
forum_form_submit($form, &$form_state);
print_r(drupal_get_messages());

This link doesn't helped me and there is nowhere on the web where the answer is explicitely given. How to programmatically create forums and containers (not forum topics)?

Thanks for helping

1 Answer 1

2

There is no need for any custom php here. Just the below steps.

In Rules actions,

  1. Action 1: "Create a new entity > Taxonomy term"
  2. Enter your title based on the created node and put it in the forum taxonomy
  3. Action 2: "Set a data value > [entity-created:parent], Value: 194"
6
  • Really thanks, I had to set [forum-created:parent] as data for action 2. But works great !
    – Aporie
    Aug 23, 2016 at 10:23
  • @VictorBourgade if this answer help you don't forget check it as accepted, if you don't know how read this drupal.stackexchange.com/tour Aug 26, 2016 at 11:44
  • Hey Niall, correct me if I'm wrong, but from your interesting answer I seemm to understand that there is no need for some PHP script (as in the question), or am I missing something? If I'm right, I think you should somehow indicate that also in your answer. PS to @AdrianCidAlmaguer : looks like your comment here has been obsoleted ... Nov 13, 2016 at 9:45
  • 1
    Yeah, this answer covers the creation of a forum without the Php. I'll edit now. Nov 13, 2016 at 10:15
  • Merci for clarifying Niall. But whillle you're at it, maybe you should also add like a note or so to explain that If in Action 1 you don't use "entity_created", but "forum_created" instead, then that implies you also have to set [forum-created:parent] as data for action 2 (as in the comment from OPer below this answer). At least that's my best guess why OPer needed that minor tweak as in the comment, no? Nov 13, 2016 at 10:49

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.