Hi,
ive been using ctools to display forms in popup modal dialogs,
can i use ctools for displaying nodes and 'Views' too? or is it only for forms?

Comments

firdous.ali86’s picture

is there a function like ctools_modal_page_wrapper()? well obviously there isnt, but any function that does render the page to display in a modal

nevets’s picture

Ctools includes some examples, I thought there was a non-form example.

firdous.ali86’s picture

while going through modal.inc i learnt how to do it, i simply had to use ctools_modal_render($title, $output) to print my modal dialog, its great tool :)

FIrdous

hmdnawaz’s picture

Can you further explain this ctools_modal_render($title, $output) a bit more please? i want to have a popup modal having comments form in it. i am using drupal 7.

Ahmad Nawaz
Acquia Certified Developer
Email: hmdnawaz@gmail.com
Skype: hmdnawaz

firdous.ali86’s picture

Hi,
This question was for popup modals in which there is no form, for forms example you can see the ctools ajax example module that comes with the ctools module.
Thanks,
Firdous

yarthesh’s picture

Subscribe

couturier’s picture

couturier’s picture

firdous_kind86 would you please share the entire code plus the link you used to activate the modal? I am not an experienced programmer and would really appreciate seeing this all put together in one place correctly. The CTools documentation is confusing to me. I've spent days on this since November 2011 and asked for help from lots of people. No one seems to know yet exactly how to solve the problem, but you sound like you had success. I just want to bring up a node in a modal. Thanks.

shadcn’s picture

Here are some codes to render a node inside a ctools modal :

/**
 * Implements hook_menu()
 */
function MYMODULE_menu() {
  $items = array();
  
  $items['modal/%ctools_js/view/%node'] = array(
    'title' => t('View Node'),
    'page callback' => 'MYMODULE_view_node',
    'page arguments' => array(1, 3),
    'access callback' => TRUE,
  );
  
  return $items;
}

function MYMODULE_view_node($js = NULL, $node) {
  // Fall back if $js is not set.
  if (!$js) {
    return drupal_access_denied();
  }
  
  $title = $node->title;
  $output = drupal_render(node_view($node, 'full'));
  
  if ($js) {
    ctools_include('ajax');
    $commands = array();
    $commands[] = ctools_modal_command_display($title, $output);
    print ajax_render($commands);
    exit;
  }
  else {
    return $output;
  }
}
couturier’s picture

Thanks, Arshad. I tried the code you listed, and I'm still having to add the following to activate a modal:

ctools_include('modal');
ctools_modal_add_js();

Also, I'm not sure how to format a link to the node. This does not work:

<a class="ctools-use-modal" href="/js/node/[nid]">Modal Test</a>

Please forgive me for being so simple, here. I'm not a programmer, but I would really like to make a modal work. Thanks.

shadcn’s picture

You can use this to create a link

print ctools_modal_text_button(t('Modal Test'), 'modal/nojs/view/NIDHERE');
couturier’s picture

Thanks, Arshad. I think I need to learn more about php, because I'm getting an error, a call to an undefined function. Trying to create a modal is hard for a non-programmer like me, but I have a book on Ajax and PHP that I need to read. Maybe that will help me. Thanks for your code. I plan to keep trying.

quano1’s picture

i'm looking for a long time to create modal form via ctools...
but it always return this error:
[{"command":"settings","settings":{"basePath":"\/drupal-7.19\/","pathPrefix":"","ajaxPageState":{"theme":"bartik","theme_token":"L8sJ_9AZ1jEHhPEfo85PkDBreUd9_uWXDqhyv6Ru_so"},"overlay":{"paths":{"admin":"node\/*\/edit\nnode\/*\/delete\nnode\/*\/revisions\nnode\/*\/revisions\/*\/revert\nnode\/*\/revisions\/*\/delete\nnode\/add\nnode\/add\/*\noverlay\/dismiss-message\nuser\/*\/shortcuts\nadmin\nadmin\/*\nbatch\ntaxonomy\/term\/*\/edit\nuser\/*\/cancel\nuser\/*\/edit\nuser\/*\/edit\/*","non_admin":"admin\/structure\/block\/demo\/*\nadmin\/reports\/status\/php"},"pathPrefixes":[],"ajaxCallback":"overlay-ajax"}},"merge":true},{"command":"modal_display","title":"About Us","output":"\u003Cdiv id=\u0022node-1\u0022 class=\u0022node node-page node-promoted node-sticky contextual-links-region clearfix\u0022 about=\u0022\/drupal-7.19\/node\/1\u0022 typeof=\u0022foaf:Document\u0022\u003E\n\n \u003Ch2 property=\u0022dc:title\u0022 datatype=\u0022\u0022\u003E\n \u003Ca href=\u0022\/drupal-7.19\/node\/1\u0022\u003EAbout Us\u003C\/a\u003E\n \u003C\/h2\u003E\n \u003Cdiv class=\u0022contextual-links-wrapper\u0022\u003E\u003Cul class=\u0022contextual-links\u0022\u003E\u003Cli class=\u0022node-edit first\u0022\u003E\u003Ca href=\u0022\/drupal-7.19\/node\/1\/edit?destination=happy\/ajax\/1\u0022\u003EEdit\u003C\/a\u003E\u003C\/li\u003E\n\u003Cli class=\u0022node-delete last\u0022\u003E\u003Ca href=\u0022\/drupal-7.19\/node\/1\/delete?destination=happy\/ajax\/1\u0022\u003EDelete\u003C\/a\u003E\u003C\/li\u003E\n\u003C\/ul\u003E\u003C\/div\u003E\n \n \u003Cdiv class=\u0022content clearfix\u0022\u003E\n \u003Cdiv class=\u0022field field-name-body field-type-text-with-summary field-label-hidden\u0022\u003E\u003Cdiv class=\u0022field-items\u0022\u003E\u003Cdiv class=\u0022field-item even\u0022 property=\u0022content:encoded\u0022\u003Eafasdfasdf\u003C\/div\u003E\u003C\/div\u003E\u003C\/div\u003E \u003C\/div\u003E\n\n \n \n\u003C\/div\u003E\n"}]
i'm copy almost of your code

function happy_menu() {
	$items['happy/%ctools_js/%'] = array(
			'title' => 'The Happy Modal',
			'page arguments' => array(1, 2),
			'page callback' => 'happy_modal_page',
			'access callback' => TRUE,
			'type' => MENU_NORMAL_ITEM,
	);
	return $items;
}

function happy_modal_page($js = NULL, $nid = NULL) {
	if ($nid == NULL) {
		// You can customize the string below, or use a drupal_goto() to
		// send the user to a custom error page.
		return 'No node id was sent. Error.';
	}
	// Load the node obkect
	$node = node_load($nid);
	$title = $node->title;
	// Drupal 7 requires a render of the node object in order to obtain a string.
	// Note that I am able to customize the fields by using the "Teaser" display mode
	// under admin/structure/types.
	$contents = drupal_render(node_view($node, 'full', NULL));
	if ($js) {
		// Required includes for ctools to work:
		ctools_include('modal');
		ctools_include('ajax');
// 		return ctools_modal_render($node->title, $contents) ;
		$commands = array();
		$commands[] = ctools_modal_command_display($title, $contents);
		print ajax_render($commands);
		exit;
	}
	else return $contents;
}

the link to access is: localhost/happy/ajax/1
nojs, js or any text argurment means $js=0. only 'ajax' argument means $js=1
PLEASE HELP!

quano1’s picture

my environtment:
fresh drupal 7.19 (no more contrib module)
lastest views
lastest ctools
ubuntu 12.04
debug both of chrome or firefox
i tried to fix this error in 2 weeks and no result. too much tired

couturier’s picture

@quano1 If you are having a hard time, I suggest you do something different than using a modal. Modals require a lot of knowledge, and there is currently no easy module to help implement specialty situations.

quano1’s picture

thank you, but modal form is so much powerful at now, isn't it?
I think I have no choice

quano1’s picture

yeah. the only way i know just now is use this fuction:
print ctools_modal_text_button(t('title'),'/happy/nojs/1',t('alt'));
2 weeks for this solution..

tmsss’s picture

I am getting an ajax error:
An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: http://localhost/restylr/node/ajax/10
StatusText: error
ResponseText: Recoverable fatal error: Object of class stdClass could not be converted to string in DatabaseStatementBase->execute() (line 2168 of /opt/lampp/htdocs/restylr/includes/database/database.inc).

Does anyone knows a solution for this?

vikrama1k1’s picture

To render a FORM in Ctools popup use function :
ctools_modal_form_wrapper('myform',$form_state);
To render a VIEW in Ctools popup :
//write this code in your ajax callback function its help you
$output = views_embed_view('yourview','page');
return ctools_modal_render($output);