Hello,

I want to start off by thanking all of you in advance for reading this and trying to help me out. Please confirm that I have posted this in the correct place as this is the first issue I've posted. This I'm guessing is related to the "add entity to group" action which is why I've put it here.

My goal is to use Rules to add a 'default' vocabulary to each group that is created. I'm certainly not an expert with Rules but imagine this should be pretty simple? The research I've done in this issue queue and in general hasn't provided any solution even though one seems to be what I would need: #512488: when an og is created automatically create an og vocabulary for it with the same name (see post #4). As described in #8 I have left the variables as default.

What I have assumed is correct is the following:

  • Event: After Saving New Content
  • Condition: Content is of type (Parameter: Content: [node], Content types: Partner)
  • Action 1: Create a new entity (Parameter: Entity type: Taxonomy vocabulary, Name: Buildings, Machine name: buildings
    Provides variables: Created entity (entity_created)) I have attempted using the "Add a variable" action as well with no luck.
  • Action 2: Add entity to group

Action 2 is where the problem lies as far as I can tell. The entity data selector only provides entity-created:. My limited understanding is that Rules is looking for data that isn't available for some reason - but I don't know what else it is expecting or why. Of course, removing this colon results in "The data type of the configured argument does not match the parameter's entity requirement." The group data selector is set to node.

If any other information would be helpful to you please don't hesitate to ask. Thank you!

Comments

acrollet’s picture

Title: Assigning vocab to group with rules » Add rule action to create OG Vocabulary
Category: support » feature
Status: Active » Needs review
StatusFileSize
new2.2 KB

I was trying to do this as well, and could not find any incantation to persuade rules to do this. So, I created a rule action for adding a new OG vocab to a group that meets the use case suggested by OP.

tdwhite’s picture

Status: Needs review » Reviewed & tested by the community

Works beautifully! Thanks for your help. I think if there's the ability to add terms to that vocabulary with Rules then this should certainly be committed.

amitaibu’s picture

Thanks, but the rule action should be against OG 2.x

acrollet’s picture

Status: Reviewed & tested by the community » Needs work

setting status - really the rule should have a way to affect the widget options too, but I don't have time work on adding that...

tdwhite’s picture

@Amitaibu I patched with git and am running OG 2.x. No issues from what I could tell - perhaps I misunderstand. :)

amitaibu’s picture

Status: Needs work » Needs review

Ok, sorry thought it was against 1.x. Back to needs review.

skyredwang’s picture

Status: Needs review » Reviewed & tested by the community

#1 patch works

aleck_wi’s picture

for me too.
thanks

wastrilith2k’s picture

Has anyone figured out how to set the status to Enabled?

wastrilith2k’s picture

I had to hack the actual og_vocab module to do this as I couldn't determine how to override $og_vocab->is_new.

My issue now is that whenever I create a new og node, it displays EVERY vocabulary on the screen. It seems like it's adding the Entity Reference to OG_vocabulary back to the content type every time I save. I've deleted it from the content type itself as well as from the admin/config/group/fields screen.

wastrilith2k’s picture

Nevermind, it was how I was setting the status to 1 that was causing an issue. I removed that from this patch and just hard coded the default value of status to enabled and that seems to be working. I don't anticipate disabling it so I won't work on a work-around at this point.

Update:

Nevermind, it still shows any OG Vocabularies when I use the rule to create them. It also automatically adds the OG Vocabularies widget to the group content type.

--James

nwom’s picture

Thanks so much for the patch. I'm currently testing it out now. Would it be possible to also include a rule to automatically delete the vocab and all terms when the OG gets deleted?

I'm currently using https://drupal.org/project/OG-Delete to delete all associated nodes already.

Thanks in advanced.

acrollet’s picture

NWOM: let's try and get this patch reviewed and in on its own merits, and deal with any other rules as separate feature requests.

kolier’s picture

Do you think it should separate the Name/Machine Name in the action, not just automatically generate the machine name?

solesum’s picture

#1 patch worked for me

solesum’s picture

Would be extra awesome if this action also provided a variable for the created vocab too!!

gaëlg’s picture

Patch #1 will associate a vocabulary to the group but the use of this vocabulary on group content editing will require manual enabling.
Correct if I'm wrong, but unless in the specific case of nested groups, this is useless:

  // Create the OG Vocabulary.
  $group_type = $entity_type;
  $og_vocab = og_vocab_create_og_vocab($vocab->vid, $entity_type, $entity->type);
  $og_vocab->save();

The OG vocabulary entity reference field should be associated to the group type but to the group content type.

What about adding a parameter to the rule to define the entity type/bundle that should use OG vocabulary?
Something like this in hook_rules_action_info :

     'group_content_types' => array(
        'type' => 'list<text>',
        'label' => t('Group content types'),
        'wrapped' => TRUE,
        'options list' => 'og_vocab_rules_group_content_types_options',
      ),

and this code instead of the previously quoted code:

function og_vocab_rules_action_create_vocab($group, $name, $description = '', $group_content_types = array(), $settings) {
(...)
  // Create the OG Vocabularies.
  foreach ($group_content_types->value() as $option) {
    list($group_content_entity_type, $group_content_bundle) = explode(':', $option);
    $og_vocab = og_vocab_create_og_vocab($vocab->vid, $group_content_entity_type, $group_content_bundle);
    $og_vocab->save();
  }

and this function as options callback:

/**
 * Options callback for create OG Vocabulary Rules action.
 */
function og_vocab_rules_group_content_types_options() {
  $options = array();
  foreach (entity_get_info() as $entity_type => $entity_value) {
    foreach ($entity_value['bundles'] as $bundle => $bundle_value) {
      if (og_is_group_content_type($entity_type, $bundle)) {
        $options[$entity_type . ':' . $bundle] = check_plain($entity_value['label']) . ' - ' . $bundle_value['label'];
      }
    }
  }
  return $options;
}

PS: I don't provide a patch because providing the entire .rules.inc file as a patch would not highlight the change, and I'm not very comfortable with patches of patches.

gaëlg’s picture

Status: Reviewed & tested by the community » Needs review
realityloop’s picture

Path with GaëlG's suggestions attached

realityloop’s picture

There was an error in GaëlG's logic, fixed in attached patch

realityloop’s picture

Added ability to configure widget settings

zorax’s picture

it is possible to have a widget for adding terms in node-form?
I add your rule when the group is created, but the user can't not add term whatever the widget.
i tested "Autocomplete term widget" "hierarchical select", and "entity reference tree".