You are here

function modal_node_edit_page_add in Modal operations 7

Page callback - modal: add node.

1 string reference to 'modal_node_edit_page_add'
modal_node_edit_menu in modal_node_edit/modal_node_edit.module
Implements hook_menu().

File

modal_node_edit/modal_node_edit.module, line 72
Allows node editing, adding and deleting in modal window.

Code

function modal_node_edit_page_add($type, $js, $force_page_reload = TRUE) {

  // Fall back if $js is not set.
  if (!$js) {
    $parameters = drupal_get_query_parameters();
    unset($_GET['destination']);
    drupal_goto('node/add/' . str_replace('_', '-', $type), array(
      'query' => $parameters,
    ));
    return NULL;
  }
  $types = node_type_get_types();
  if (!isset($types[$type])) {
    $parameters = drupal_get_query_parameters();
    unset($_GET['destination']);
    drupal_goto('node/add/' . str_replace('_', '-', $type), array(
      'query' => $parameters,
    ));
    return NULL;
  }
  $type_name = $types[$type]->name;

  // Fix superglobals (such as $_GET) in order to make arg() work properly.
  modal_set_path_data('node/add/' . str_replace('_', '-', $type));
  ctools_include('modal');
  ctools_include('ajax');
  if (!node_access('create', $type)) {
    $commands = array(
      ctools_modal_command_display(t('Access denied'), t('You are not authorized to access this page.')),
    );
    $commands[] = ajax_command_invoke('#modalContent', 'addClass', array(
      'modal-denied-node-add modal-denied-node-add-' . $type,
    ));
    drupal_alter('modal_node_edit_page_add_access_denied', $commands, $type, $type_name);
    return array(
      '#type' => 'ajax',
      '#commands' => $commands,
    );
  }
  global $user;

  // Node object skeleton..
  $node = (object) array(
    'uid' => $user->uid,
    'name' => isset($user->name) ? $user->name : '',
    'type' => $type,
    'language' => LANGUAGE_NONE,
  );
  $title = t('Create @name', array(
    '@name' => $type_name,
  ));
  drupal_alter('modal_node_add_title', $title, $type, $type_name);
  return modal_node_edit_node_form($node, $title, $force_page_reload);
}