The basic problem is when using a modal with a form all works great except when javascript is disabled.

When js is disable the page just shows a bunch of setting.

I figured out the root of the problem for this was due to the page arguments in hook_menu.

This is what I was using then I changed the page arguments to only point to %ctools... And thus the issue went away... Or so it seems.

  $items['node/%node/%ctools_js/delete'] = array(
    'title' => 'Delete Newslink', 
    'page callback' => 'newslink_modal_delete_confirm',
    // Original page arguments.
    //  'page arguments' => array(1, 2),
    // New page arguments.
    'page arguments' => array(2),
    'access callback' => 'node_access', 
    'access arguments' => array('delete', 1), 
    'type' => MENU_CALLBACK,
    'file' => 'node.pages.inc',
    'file path' => drupal_get_path('module', 'node'),
  );

Can anyone please tell me why this is just to help me further understand for future reference?

Thank you in advance.

Comments

merlinofchaos’s picture

Status: Active » Postponed (maintainer needs more info)

I have no idea without being able to see the code behind it. Obviously this is a custom menu entry and presumably has custom code behind it.

merlinofchaos’s picture

My best guess is that your callback isn't properly set up to react to the arguments.

walker2238’s picture

I'm sorry...

function newslink_modal_menu() {
  $items = array();

  $items['node/%node/%ctools_js/delete'] = array(
    'title' => 'Delete Newslink', 
    'page callback' => 'newslink_modal_delete_confirm',
    'page arguments' => array(2),
    'access callback' => 'node_access', 
    'access arguments' => array('delete', 1), 
    'type' => MENU_CALLBACK,
    'file' => 'node.pages.inc',
    'file path' => drupal_get_path('module', 'node'),
  );

  return $items;
}
function newslink_modal_node_view($node, $view_mode, $langcode) {
  $links = array();
  global $user;
  
  ctools_include('ajax');
  ctools_include('modal');
  ctools_modal_add_js();
  
  $custom_style = array(
    'ctools-sample-style' => array(
      'modalSize' => array(
        'type' => 'fixed',
        'width' => 535,
        'height' => 250,
      ),
      'animation' => 'fadeIn',
    ),
  );
  drupal_add_js($custom_style, 'setting');

  ctools_include('plugins');  
  
  if ((user_access('delete own newslink content') && $user->uid == $node->uid) || user_access('delete any newslink content')) {
    $links['newslink-modal-delete'] = array(
      'title' => ctools_modal_text_button(t('Delete'), "node/$node->nid/nojs/delete", NULL, 'ctools-modal-ctools-sample-style'),
      'html' => TRUE,
    );
  }
  
  $node->content['links']['newslink_modal'] = array(
    '#theme' => 'links__node__newslink_modal',
    '#links' => $links,
    '#attributes' => array('class' => array('links')),
  );
}

And my callback...

function newslink_modal_delete_confirm($js = NULL) {
  // Don't need this because we include is in hook_menu().
  // module_load_include('inc', 'node', 'node.pages');
    
    $nid = arg(1);
    $node = node_load($nid);

  if (!$js) {
    return drupal_get_form('node_delete_confirm', $node);
  }

  ctools_include('modal');
  ctools_include('ajax');
 
  $form_state = array(
    'title' => t('Delete Newslink'),
    'ajax' => TRUE,
  );

  $form_state['build_info']['args'][] = $node;
  
  $output = ctools_modal_form_wrapper('node_delete_confirm', $form_state);

  print ajax_render($output);
  exit;

}
merlinofchaos’s picture

Status: Postponed (maintainer needs more info) » Fixed

    'page callback' => 'newslink_modal_delete_confirm',
    // Original page arguments.
    //  'page arguments' => array(1, 2),
    // New page arguments.

What the above original page arguments are doing are sending the first argument (the loaded node) and the second argument (whether or not it's $js) to the function. However, your callback is declared like this:


function newslink_modal_delete_confirm($js = NULL) {
  // Don't need this because we include is in hook_menu().
  // module_load_include('inc', 'node', 'node.pages');
    
    $nid = arg(1);
    $node = node_load($nid);

  if (!$js) {
    return drupal_get_form('node_delete_confirm', $node);
  }

It is set up to receive only 1 argument. What was probably happening is that $js is receiving the node, and thus $js always appears TRUE when used as a boolean.

What you really want is this:


function newslink_modal_delete_confirm($node, $js = NULL) {
  if (!$js) {
    return drupal_get_form('node_delete_confirm', $node);
  }

That will allow you to not load the node based on arg(1) and properly receive the $js option.

walker2238’s picture

Ah, that makes everything so much clearer... Makes a lot of sense. Thank you for your time.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Missing php tags.