Hi:

It would be nice to have a generic page for selecting the node type we want to create (like node/add but only with the content types we can create in that group) so we can put a link named 'create content' in the details block and perhaps remove the 'create xxxx' links.
This is more usable since the user is presented with a textual description of each content type he can create and reduces the number of links in the details block.

You don't have to change the details block you don't want but the page would be useful anyway...

Thanks.-

CommentFileSizeAuthor
#3 og_user_roles.module.5.x-2.7.patch12.43 KBsomebodysysop

Comments

moshe weitzman’s picture

Status: Active » Closed (won't fix)

a contrib module ought to do this.

neurojavi’s picture

Project: Organic Groups » OG User Roles
Version: 5.x-4.3 » 5.x-2.6
Component: og.module » Code
Assigned: Unassigned » neurojavi
Status: Closed (won't fix) » Needs review

Hi!

Sorry moshe, you're right. This feature can be implemented in user roles module since this module deals with a modified version of node add.

I have write some code for this page to be shown and to show a new link "Create content" in de group details block:

Changed og_user_roles_ognodeadd() function (note the new else after the if ($type) { ... })

/**
 * Create content
 * Format: http://www.scbbs.com/node/ognodeadd?type=link&gids[]=29
 */
function og_user_roles_ognodeadd() {
  global $user;

  $roles = og_user_roles_all_roles($user); // This returns normal $user->roles and includes OG roles if any

  $user->roles = $roles;
  $gids = $_GET['gids'];
  if ($gids) {
     $group_node = node_load($gids[0]);
     og_set_group_context($group_node);
  }

  $type = $_GET['type'];

  if ($type) {
    // Got this from node.module (node_access)
    // No matter the type, this should return us the create permission.
    $module = node_get_types('module', $type);

    if ($module == 'node') {
      $module = 'node_content'; // Avoid function name collisions.
    }

    $access = module_invoke($module, 'access', 'create', $type);

    if ($access === TRUE) {
    // Working on this issue: http://drupal.org/node/183096
      $content_type = node_get_types('type', str_replace('-', '_', $type));
      $output = '<p>'. filter_xss_admin($content_type->help) .'</p>';
      $output .= node_add($type);
    }
    else {
      $output = 'Access denied.';
      watchdog('access denied', 'node/ognodeadd?type='. $type .'&gids[]='. $gids[0], WATCHDOG_WARNING);
    }
  }else{
    // Modification: Creates an overview page with the allowed node types for this user and group 
    // when there is no type in the url query. This page is similar to generic node/add page
    // Taken and modified from node_add() function in node core module and og_og_create_links() in og module
    // If no (valid) node type has been provided, display a node type overview.
    $exempt = array_merge(variable_get('og_node_types', array('og')), variable_get('og_omitted', array()));
    foreach (node_get_types() as $type) {
      // we used to check for node_access(create) but then node admins would get a false positive and see node types that they could not create
      if (!in_array($type->type, $exempt) && module_invoke(node_get_types('module', $type), 'access', 'create', $type)) {
        $type_url_str = str_replace('_', '-', $type->type);
        $title = t('Add a new @s.', array('@s' => $type->name));
        $out = '<dt>'. l(drupal_ucfirst($type->name), "node/add/$type_url_str", array('title' => $title), 'gids[]='. $gids[0]) .'</dt>';
        $out .= '<dd>'. filter_xss_admin($type->description) .'</dd>';
        $item[$type->type] = $out;
      }
    }

    if (isset($item)) {
      uksort($item, 'strnatcasecmp');
      $output = t('Choose the appropriate item from the list:') .'<dl>'. implode('', $item) .'</dl>';
    }
    else {
      $output = t('No content types available.');
    }
  }

  return $output;
}

And this funtion provides the new "create content" link:

// $group is an object containing the group node
function og_user_roles_og_create_links($group) {
  $links[] = l(t('Create content'), "node/add", array('title' => t('Add new content in this group.')), "gids[]=$group->nid");
  return $links;
}

I know that perhaps this is not the module for this kind of user interface enhancements but there is the only easy way to go without replicating all you 'node add groupication' code. If you like this patch I'll post another feature request about porting some common code to another module.

Thanks to moshe and SomebodySysop for his clean code. It's very nice to work with it!

somebodysysop’s picture

StatusFileSize
new12.43 KB

Pretty slick piece of code. I was going to ask why would anyone want this, but I just went ahead and tried it out and it works pretty cool. EXCEPT, this bit:

        // Why is this needed?
        // $type_url_str = str_replace('_', '-', $type->type);
        $type_url_str = $type->type;

Apparently, the node/add process will change "-" back to "_", but ognodeadd doesn't, so I had to remove this. If someone else out there knows why this is in the node.module in the first place, and possible ramifcations of removing it, I'd like to know.

Other than that, really good work. Thanks for taking the time to put it together

Please test out the patch and let me know if it works for you! Note that the patch must be applied to a clean download of OGR 2.6 release.

somebodysysop’s picture

Version: 5.x-2.6 » 5.x-2.7
Status: Needs review » Fixed

This patch now included in latest OGR release.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.