I am trying to set up a rule that creates a new vocabulary when a new node is created. The only problem is there is nothing in the replacement patterns I can trust to be always unique for the machine name.
I posted a while back in the Rules group (http://groups.drupal.org/node/174784) and I couldn't find a solution since then.
Any help would really be appreciated.

Comments

gmclelland’s picture

Component: Rules Core » Rules Engine

This is happening to me as well.

el1_1el’s picture

Component: Rules Engine » Rules Core

a bit late on this thread but i was trying to do the exact same thing and had the exact same problem.

The only way i could figure out to accomplish the auto vocab creation was to comment out all the checks in function checkParameterSettings in rules core.inc, then jam a valid value into the machine name without rules checks (has to start with letters, no spaces etc). so I then select node:title for the machine name (my og group name is the group node title name), strip out extra characters in php and return the value in php evaluation.

$value = strtolower($value);
$value = preg_replace("/[^a-z]/", "", $value);
return $value;

i'm not thrilled with this hacky way of doing it so if anyone runs across this and has a better idea i'd love to hear it!

yooh’s picture

Hi all,

anyone find better solution for this bug ?
rules 7.x-2.3

bastnic’s picture

Same problem here. Caused by the machine field being a "token" field. Which does not permit to have a token transformation. Quick ugly patch, and I can use a token like vocabulary_for_node_[node:nid] as machine name. Like I said, quick and dirty.

index 0f4c36a..21b05e6 100644
--- a/modules/entity.eval.inc
+++ b/modules/entity.eval.inc
@@ -111,6 +111,7 @@ function rules_action_entity_create_info_alter(&$element_info, RulesAbstractPlug
         $element_info['parameter']['param_' . $name]['options list']  = $child->optionsList() ? 'rules_action_entity_parameter_options_list' : FALSE;
       }
     }
+    $element_info['parameter']['param_machine_name']['type'] = 'text';
     $element_info['provides']['entity_created']['type'] = $element->settings['type'];
     if (($bundleKey = $wrapper->entityKey('bundle')) && isset($element->settings['param_' . $bundleKey])) {
       $element_info['provides']['entity_created']['bundle'] = $element->settings['param_' . $bundleKey];
solesum’s picture

This issue seems to completely get in the way of creating vocabularies via Rules... I wonder if the above patch is okay to use?

solesum’s picture

I've spent way too many days trying to solve this, so I thought I would see if anyone can help. I am very grateful that others here have figured out workarounds via hacking rules and entity, but sadly I can't use those hacks because our site will updated/maintained by a third party who won't keep track of them. If I am patching, those patches need to eventually be committed to a release. If anyone has any ideas to help at all, I would be most grateful!

Just to restate the issue. When I use rules to "Create a new entity > taxonomy vocabulary" on saving a new group, I am prompted to enter a value for the vocabulary machine name. However, only tokens of the type "text-token" are available, and none of them are unique. So, because of this, my rule will only work once, for the first group, because it is only able to use the machine name once (because it's not a unique machine name).

Here's what I have already tried:

1. I installed and tested both the Safeword and Machine Name modules, using each of them respectively to create a correctly formatted machine name. I then attempted to use these as replacement text-tokens with Rules, but it turns out neither of these modules actually create a real, text-token type machine name that's available to Rules.

2. I thought I might be able to use Rules to convert these text-based machine names to text-tokens via the "convert data type" action -- not possible. I also thought I might be able to change the machine names after the fact, but ran into the same issue as above.

3. It seemed like the OG Vocabulary module would solve my problems, and I installed this patch to create the desired vocabulary. It does work, creating a matching vocabulary per group. However, the relationship/reference it builds to the group node is inaccessible via Views, preventing me from being able to use Views to organize group content in the way I intend. https://drupal.org/node/1963898. I wish I had an entity reference or a group audience field to work with, but there are no relationships available.

4. I back-pedaled and tried to use a single vocab with parent terms which have a groups audience, but this isn't desirable because I need group managers to be able to manage just their vocabulary, independently of other groups' vocabularies (these vocabularies are serving as "course outlines" to organize group nodes).

- - -
It seems like Rules wants to do this for me, and I wonder if my lack of PHP skills is what's preventing me from getting this to work. I think the best solution might be to append some kind of unique string or ID to the machine name, in direct input mode or via php, to build a custom token that can be unique. Is that possible? Is there anyone with enough coding skills to help me out with this?

In the original asker's post in Drupal Groups (https://groups.drupal.org/node/174784) they also tried this by adding some code, but it didn't work either.

Even if someone is able to let me know if this is possible, that would be a help!