You are here

function noderelationships_noderef_page_create in Node Relationships 6

Build the create and reference page.

See also

node_add_page()

node_add()

_noderelationships_child_node_form_alter()

_noderelationships_child_node_form_submit()

1 call to noderelationships_noderef_page_create()
noderelationships_noderef_page in ./noderelationships.pages.inc
Menu callback; Search or Create and reference.

File

./noderelationships.pages.inc, line 368
Implementation of user land pages.

Code

function noderelationships_noderef_page_create($referrer_type, $field_name, $new_type) {
  $reference_fields = noderelationships_get_reference_fields($referrer_type);
  if (isset($reference_fields[$field_name])) {

    // Build the list of content types related to the given parent node type,
    // and nodereference field, that can be created by the current user.
    $creatable_types = noderelationships_get_creatable_types($referrer_type);

    // Do we know the content type the user wants to create?
    if (empty($new_type)) {

      // Display the list of content types that can be referred from the
      // given field in the current parent content type.
      $node_add_list = array();
      foreach ($reference_fields[$field_name] as $new_type) {
        if (isset($creatable_types[$new_type])) {
          $translated_menuitem = menu_get_item('node/add/' . str_replace('_', '-', $new_type));
          if (!empty($translated_menuitem)) {
            $translated_menuitem['href'] = 'noderelationships/create/' . $referrer_type . '/' . $field_name . '/' . $new_type;
            $translated_menuitem['localized_options']['attributes'] = array(
              'class' => 'modalframe-exclude',
            );
            $query = noderelationships_querystring();
            if (!empty($query)) {
              $translated_menuitem['localized_options']['query'] = $query;
            }
            $node_add_list[] = $translated_menuitem;
          }
        }
      }

      // Only display the content type selection screen if more than one
      // type is available.
      if (count($node_add_list) > 1) {
        return theme('node_add_list', $node_add_list);
      }
    }

    // And now? Do we know the content type the user wants to create?
    if (!empty($new_type)) {

      // Let's try to redirect to a regular node/add form for the specified type.
      if (isset($creatable_types[$new_type])) {
        $_GET['noderelationships_referrer_type'] = $referrer_type;
        $_GET['noderelationships_field_name'] = $field_name;
        $query = drupal_query_string_encode($_GET, array(
          'q',
        ));
        unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
        drupal_goto('node/add/' . str_replace('_', '-', $new_type), $query);
      }
    }
  }
}