1

How is possible to create a content type associated by default to a group in Drupal Commons?

I will try to explain. I have two groups: literature and art. Literature will have three content types i.e. poetry, fiction and novels. Art will have painting, photography and drawings.

I've created contents types and i've tried to associate them with the respective group by flagging the group and group content checkbox but nothing changed. I also followed the steps described here https://www.drupal.org/node/2014781 but when I try to add some content I still see the "Post to specific groups" radio option and select.

Help please!!!

0

1 Answer 1

0

I am assuming you are using one group content type, and "Literature" and "Art" are contents of that group type.

Tell me if I am wrong in my assumption.

You can use hook_form_BASE_FORM_ID_alter() to set a default field value for group field based current content type.

    function mymodule_form_node_form_alter(&$form, &$form_state) {
      $node = $form_state['node'];
      if (!isset($node->nid) || isset($node->is_new)) {
       global $user;
       $groups = og_get_groups_by_user($user);
          if(is_array($groups)) {
          // This needs to be evaluated to check proper mapping of what field expect to set a default default field value
          if($node['#bundle'] == "poetry" || $node['#bundle'] == "fiction" ||$node['#bundle'] == "novels") {
          $form['group_field_name']['#default'] = $groups[0];  //Whatever index Literature has 
          }
          elseif($node['#bundle'] == "painting" || $node['#bundle'] == "photography" ||$node['#bundle'] == "drawings") {
          $form['group_field_name']['#default'] = $groups[1];  // Art's index
          }
          }
      }
    }
14
  • Hi Chetna tks for your reply. I've two groups literature and art and i've tried to force the content types poetry, fiction and novels to write only in the Group literature and painting, photography and drawings to write only in the Group Art
    – Emanuele
    Commented Sep 28, 2015 at 14:25
  • I've created two new Content Types respectively Literature and Art and in the OG tab i've flagged Group and Group content. So in the Target bundles list now i've Group, Literature and Art. Then i've created other three content types poetry, fiction and novels flagged as a Group content, selected the Literature Group form the Target bundles list and finally created the new Tabs for the Commons browsing widget user interface but this keep on write in all groups.
    – Emanuele
    Commented Sep 28, 2015 at 15:06
  • So, Literature and Art are two different content types and they are getting them listed in Target bundles list other group contents (painting, photography, drawings, poetry, fiction, novels). So, now what you need to do is just to select "Literature" in Target bundle of poetry, fiction and novels content types, and save, and similarly select "Art" in Target bundle of painting, photography and drawings content types, and save. This will do what you want.
    – Dev
    Commented Sep 29, 2015 at 4:26
  • Thanks it seem to works. Now the problem is: how to show the right common browser widget tabs in the right group?
    – Emanuele
    Commented Sep 30, 2015 at 13:28
  • Hi Drupaler sorry... this will be my last question. I've create a module from your code: folder my_module and two files my_module.info and my_module.module that have your code with the right changes but commons doesn't want to install the module. where am I wrong? I'm missing some file?
    – Emanuele
    Commented Oct 8, 2015 at 16:57

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.