0

I'm wondering if there is en option to apply og membership to all the entity referenced children of an node.

I have a content type 'Enterprise' which can reference itself to create a structure of enterprises. F.e. (Enterprise 1 --> Subenterprise 1 --> Subsubenterprise 1)

When enterprise 1 is added to a group all dependent nodes should be added also.

Thanks in advance for your advice

1 Answer 1

0

You can do that with Views Rules.

  1. Create a view that gives all directly referred children of a node (with the node as contextual filter), give it a "Rules" display.
  2. Now create a Rules component that takes as argument a node, runs a "View Loop" (you'll see what that is as soon as you've installed the above mentioned module) over your newly created view.
  3. To this loop, add an action that adds the current loop item to your organic group. Save the component.
  4. Add a second action to the loop, which is the component itself, with the current loop item as an argument. (I haven't actually tried this.)
  5. You can call this rule component from within other rules that you can trigger in many ways, say by clicking a simple button or by performing a bulk operation.

My two cents:

  • Be careful with this, since it is recursive. If you have two enterprises linking each other, then this will recurse infinitely and crash. Maybe add as a precondition in the rule component that the node is not yet a member of the group.
  • Decide whether you want to use entity references or organic groups for this, but don't use both. What you're trying to do sounds a lot like you have a network of enterprises and sub-enterprises and you want to translate your existing network into organic groups. If someone adds new references, you'll have to update your groups, which is annoying. Decide between entity references and organic groups and get rid of the other.
6
  • Thanks for your advice. I will try this approach. To give you some more info on what I'm working on is a site-wide collection of Enterprises and Contacts for my organisation. For this I'm using entity reference. On the other hand my organisation is divided into departments with their own features. For this i'm using OG and Spaces. Each department must have their own set of Enterprises / contacts.
    – kim.kaho
    Sep 8, 2014 at 12:40
  • I'm struggeling to get the view loop configured in Rules. I've setup a view (rules display) with 1 contextual filter (nid of enterprise) and configured the view rules parameters/vaiables. Then I've created a rule with a view loop but when the rule is executed I receive an error: fatal error: Object of class stdClass could not be converted to string in DatabaseStatementBase->execute() (line 2171 of includes/database/database.inc).
    – kim.kaho
    Nov 6, 2014 at 9:47
  • Can you give more detail on how you've configured it?
    – Turion
    Nov 6, 2014 at 14:17
  • drupal.org/node/2370121
    – kim.kaho
    Nov 7, 2014 at 8:25
  • Shouldn't you have the nid as row variables maybe?
    – Turion
    Nov 8, 2014 at 17:58

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.