1

I have a some modal forms, the link of those embedded in views result, link are somethings linke share/nojs/2 , I register a menu in callback of the links, It work correctly for root user, but I test it with 2 authenticated user, It work correctly for one of them and in another when I click link instead open modal form redirect me to /share/nojos/2 and tell me Javascript required,according to my codes,It means the javascript not load, I really confused what happening and what can be reason of this ?

my codes :

$items['share/%ctools_js/%'] = array(
    // 'page callback' => 'ym_alter_sharing_content',
    'page callback' => 'ym_alter_sharing_callback',
    'page arguments' => array(1),
    'access callback' => 'user_is_logged_in',
    'type' => MENU_CALLBACK,
);



function ym_alter_sharing_callback($js = FALSE) {
    global $user;
// If people aren't using javascript, then I just boot em. sorry. its 2011.
    if (!$js)
        return "Javascript required";
// Include your ctools crap here
    ctools_include('node.pages', 'node', '');
    ctools_include('modal');
    ctools_include('ajax');

// Create a blank node object here. You can also set values for your custom fields here as well.
    $node = (object) array(
                'uid' => $user->uid,
                'name' => (isset($user->name) ? $user->name : ''),
                'type' => 'share',
                'language' => LANGUAGE_NONE,
    );

    $form_state = array(
        'title' => t('sharing'),
        'ajax' => TRUE,
    );

    $form_state['build_info']['args'] = array($node);
// change this to your type node form
    $output = ctools_modal_form_wrapper('share_node_form', $form_state);

// This means the form has been exectued
    if (!empty($form_state['executed'])) {
        $output = array();
// Close the modal
        $output[] = ctools_modal_command_dismiss();
// I use this method a lot on pages that have views, so what I do is get the latest view content
// with the latest node and replace the current view. magic!
        /*
          $html = views_embed_view('my_view', 'my_display';
          $output[] = ajax_command_html('.view-display-id-my_display', $html);
         */
    }
    print ajax_render($output);
    exit;
}
1

this looks like a hook_menu() implementation:

$items['share/%ctools_js/%'] = array(
// 'page callback' => 'ym_alter_sharing_content',
'page callback' => 'ym_alter_sharing_callback',
'page arguments' => array(1),
'access callback' => 'user_is_logged_in',
'type' => MENU_CALLBACK,

);

you should wrap it in a corresponding function and return menu items:

function your_module_name_menu() {
  $items['share/%ctools_js/%'] = array(
    // 'page callback' => 'ym_alter_sharing_content',
    'page callback' => 'ym_alter_sharing_callback',
    'page arguments' => array(1),
    'access callback' => 'user_is_logged_in',
    'type' => MENU_CALLBACK,
  );
  return $items;
}

other code seems to be ok. Hope this helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.