You are here

function og_node_create_links in Organic groups 7.2

Same name and namespace in other branches
  1. 7 og.module \og_node_create_links()

Return a form element with crafted links to create nodes for a group.

Parameters

$group_type: The entity type of the group.

$gid: The group ID.

$field_name: The group audience field name.

$destination: (optional) The destiantion after a node is created. Defaults to the destination passed in the URL if exists, otherwise back to the current page. FALSE to not append any destination to node create links.

$types: (optional) An array of type names. Restrict the created links to the given types.

1 call to og_node_create_links()
og_node_create_links_content_type_render in plugins/content_types/node_create_links/node_create_links.inc
Render callback.

File

./og.module, line 3505
Enable users to create and manage groups with roles and permissions.

Code

function og_node_create_links($group_type, $gid, $field_name, $destination = NULL, $types = NULL) {
  if (!og_is_group($group_type, $gid)) {
    return;
  }
  $types = isset($types) ? $types : array_keys(node_type_get_types());
  foreach ($types as $type_name) {
    if (!og_is_group_content_type('node', $type_name) || !og_user_access($group_type, $gid, "create {$type_name} content")) {
      continue;
    }
    $instance = field_info_instance('node', $field_name, $type_name);
    if (empty($instance['settings']['behaviors']['prepopulate']['status'])) {

      // Instance doesn't allow prepopulating.
      continue;
    }
    $names[$type_name] = node_type_get_name($type_name);
  }
  if (empty($names)) {
    return;
  }

  // Sort names.
  asort($names);

  // Build links.
  $options = array(
    'query' => array(
      $field_name => $gid,
    ),
  );
  if ($destination) {
    $options['query']['destination'] = $destination;
  }
  elseif ($destination !== FALSE) {
    $options['query'] += drupal_get_destination();
  }
  $items = array();
  foreach ($names as $type => $name) {

    // theme_item_list's 'data' items isn't a render element, so use l().
    // http://drupal.org/node/891112
    $items[] = array(
      'data' => l($name, 'node/add/' . str_replace('_', '-', $type), $options),
    );
  }
  $element = array();
  $element['og_node_create_links'] = array(
    '#theme' => 'item_list',
    '#items' => $items,
  );
  return $element;
}