As you can see from this major performace issue #330135: menu_router_build call in hook_init is a serious performance hit, the really roadblock is og_content_type_admin_menu_alter is not getting called by drupal machinery when we need. Any attempt to make this work seem to add signficant performance penalties. So I am thinking may be hook_menu_alter is not the hook we want to use.

I am a newbie when comes to dabbling in code. so ignore me if my thoughts don't make any sense.

At a fundamental level this module is about "removing" access to create certain content types in a given group. I mean without this module all content types can be created in a group (provided they are group enabled) and this module removed that access. So we can use og_links_alter to remove the links to create those types. Which links to remove that logic can be still same.
Now this removes the links visually. A user can still type in /node/add/create_node_type link and create content that way. To prevent that we could use hook_form_alter (or hook_form_FORM_ID_alter) and prevent the form being submitted for those content type for groups. Again the logic for which group prevents what will remain same.

Any thoughts?

Comments

JamesK’s picture

Title: move away from using hook_menu_alter » Use hook_og_links_alter() to remove content types
Version: 6.x-1.0-rc1 » 6.x-1.x-dev
Category: feature » bug

By using hook_og_links_alter() this module could also stop breaking og_block_details(). I don't see what the need is for overriding the entire block when you can instead just override specific links.

JamesK’s picture

Title: Use hook_og_links_alter() to remove content types » Use hook_og_links_alter() to remove content types from og group details block
ajayg’s picture

I could be wrong here but I am suspecting there was a need in the past to override entire block since at that time OG didn't support theming og_block details or theming individual links.

But it is a moot point now and whatever we can simplify should be done now.

rismondo’s picture

Subscribing

turadg’s picture

+1 subscribe

Leeteq’s picture

Subscribing.

jvieille’s picture

Subscribing -
Overriding the group detail block does not even seem to work for me.

Josh Benner’s picture

Snippet for your module (or for maintainer to use in og_content_type_admin):

function my_module_og_links_alter(&$links, $node) {
  $sql = "SELECT octa.types_active, octa.types_allowed FROM {og_content_type_admin} octa WHERE octa.gid = %d";
  //if we're keeping track of this group, get it's active types, otherwise, get the defaults
  if (!$result = db_fetch_object(db_query($sql, $node->nid))) {
    $result = db_fetch_object(db_query($sql, 0));
  }
  $allowed_types = unserialize($result->types_allowed);
  
  foreach ($links as $key => $link) {
    if (preg_match('/^create_(?P<type>.*)$/', $key, $matches)) {
      if (!$allowed_types[$matches['type']]) {
        unset($links[$key]);
      }
    }
  }
}

A note to maintainer: you should probably make an API function that returns the status of all types for a given group NID.