ctools_ajax_sample.module
22.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
<?php
/**
* @file
* Sample AJAX functionality so people can see some of the CTools AJAX
* features in use.
*/
// ---------------------------------------------------------------------------
// Drupal hooks.
/**
* Implementation of hook_menu()
*/
function ctools_ajax_sample_menu() {
$items['ctools_ajax_sample'] = array(
'title' => 'Chaos Tools AJAX Demo',
'page callback' => 'ctools_ajax_sample_page',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
);
$items['ctools_ajax_sample/simple_form'] = array(
'title' => 'Simple Form',
'page callback' => 'ctools_ajax_simple_form',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['ctools_ajax_sample/%ctools_js/hello'] = array(
'title' => 'Hello World',
'page callback' => 'ctools_ajax_sample_hello',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['ctools_ajax_sample/%ctools_js/tablenix/%'] = array(
'title' => 'Hello World',
'page callback' => 'ctools_ajax_sample_tablenix',
'page arguments' => array(1, 3),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['ctools_ajax_sample/%ctools_js/login'] = array(
'title' => 'Login',
'page callback' => 'ctools_ajax_sample_login',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['ctools_ajax_sample/%ctools_js/animal'] = array(
'title' => 'Animal',
'page callback' => 'ctools_ajax_sample_animal',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['ctools_ajax_sample/%ctools_js/login/%'] = array(
'title' => 'Post-Login Action',
'page callback' => 'ctools_ajax_sample_login_success',
'page arguments' => array(1, 3),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['ctools_ajax_sample/jumped'] = array(
'title' => 'Successful Jumping',
'page callback' => 'ctools_ajax_sample_jump_menu_page',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function ctools_ajax_simple_form() {
ctools_include('content');
ctools_include('context');
$node = node_load(1);
$context = ctools_context_create('node', $node);
$context = array('context_node_1' => $context);
return ctools_content_render('node_comment_form', 'node_comment_form', ctools_ajax_simple_form_pane(), array(), array(), $context);
}
function ctools_ajax_simple_form_pane() {
$configuration = array(
'anon_links' => 0,
'context' => 'context_node_1',
'override_title' => 0,
'override_title_text' => '',
);
return $configuration;
}
/**
* Implementation of hook_theme()
*
* Render some basic output for this module.
*/
function ctools_ajax_sample_theme() {
return array(
// Sample theme functions.
'ctools_ajax_sample_container' => array(
'arguments' => array('content' => NULL),
),
);
}
// ---------------------------------------------------------------------------
// Page callbacks
/**
* Page callback to display links and render a container for AJAX stuff.
*/
function ctools_ajax_sample_page() {
global $user;
// Include the CTools tools that we need.
ctools_include('ajax');
ctools_include('modal');
// Add CTools' javascript to the page.
ctools_modal_add_js();
// Create our own javascript that will be used to theme a modal.
$sample_style = array(
'ctools-sample-style' => array(
'modalSize' => array(
'type' => 'fixed',
'width' => 500,
'height' => 300,
'addWidth' => 20,
'addHeight' => 15,
),
'modalOptions' => array(
'opacity' => .5,
'background-color' => '#000',
),
'animation' => 'fadeIn',
'modalTheme' => 'CToolsSampleModal',
'throbber' => theme('image', array('path' => ctools_image_path('ajax-loader.gif', 'ctools_ajax_sample'), 'alt' => t('Loading...'), 'title' => t('Loading'))),
),
);
drupal_add_js($sample_style, 'setting');
// Since we have our js, css and images in well-known named directories,
// CTools makes it easy for us to just use them without worrying about
// using drupal_get_path() and all that ugliness.
ctools_add_js('ctools-ajax-sample', 'ctools_ajax_sample');
ctools_add_css('ctools-ajax-sample', 'ctools_ajax_sample');
// Create a list of clickable links.
$links = array();
// Only show login links to the anonymous user.
if ($user->uid == 0) {
$links[] = ctools_modal_text_button(t('Modal Login (default style)'), 'ctools_ajax_sample/nojs/login', t('Login via modal'));
// The extra class points to the info in ctools-sample-style which we added
// to the settings, prefixed with 'ctools-modal'.
$links[] = ctools_modal_text_button(t('Modal Login (custom style)'), 'ctools_ajax_sample/nojs/login', t('Login via modal'), 'ctools-modal-ctools-sample-style');
}
// Four ways to do our animal picking wizard.
$button_form = ctools_ajax_sample_ajax_button_form();
$links[] = l(t('Wizard (no modal)'), 'ctools_ajax_sample/nojs/animal');
$links[] = ctools_modal_text_button(t('Wizard (default modal)'), 'ctools_ajax_sample/nojs/animal', t('Pick an animal'));
$links[] = ctools_modal_text_button(t('Wizard (custom modal)'), 'ctools_ajax_sample/nojs/animal', t('Pick an animal'), 'ctools-modal-ctools-sample-style');
$links[] = drupal_render($button_form);
$links[] = ctools_ajax_text_button(t('Hello world!'), "ctools_ajax_sample/nojs/hello", t('Replace text with "hello world"'));
$output = theme('item_list', array('items' => $links, 'title' => t('Actions')));
// This container will have data AJAXed into it.
$output .= theme('ctools_ajax_sample_container', array('content' => '<h1>' . t('Sample Content') . '</h1>'));
// Create a table that we can have data removed from via AJAX.
$header = array(t('Row'), t('Content'), t('Actions'));
$rows = array();
for($i = 1; $i < 11; $i++) {
$rows[] = array(
'class' => array('ajax-sample-row-'. $i),
'data' => array(
$i,
md5($i),
ctools_ajax_text_button("remove", "ctools_ajax_sample/nojs/tablenix/$i", t('Delete this row')),
),
);
}
$output .= theme('table', array('header' => $header, 'rows' => $rows, array('class' => array('ajax-sample-table'))));
// Show examples of ctools javascript widgets
$output .= '<h2>'. t('CTools Javascript Widgets') .'</h2>';
// Create a drop down menu
$links = array();
$links[] = array('title' => t('Link 1'), 'href' => $_GET['q']);
$links[] = array('title' => t('Link 2'), 'href' => $_GET['q']);
$links[] = array('title' => t('Link 3'), 'href' => $_GET['q']);
$output .= '<h3>' . t('Drop Down Menu') . '</h3>';
$output .= theme('ctools_dropdown', array('title' => t('Click to Drop Down'), 'links' => $links));
// Create a collapsible div
$handle = t('Click to Collapse');
$content = 'Nulla ligula ante, aliquam at adipiscing egestas, varius vel arcu. Etiam laoreet elementum mi vel consequat. Etiam scelerisque lorem vel neque consequat quis bibendum libero congue. Nulla facilisi. Mauris a elit a leo feugiat porta. Phasellus placerat cursus est vitae elementum.';
$output .= '<h3>'. t('Collapsible Div') .'</h3>';
$output .= theme('ctools_collapsible', array('handle' => $handle, 'content' => $content, 'collapsed' => FALSE));
// Create a jump menu
ctools_include('jump-menu');
$form = drupal_get_form('ctools_ajax_sample_jump_menu_form');
$output .= '<h3>'. t('Jump Menu') .'</h3>';
$output .= drupal_render($form);
return array('markup' => array('#markup' => $output));
}
/**
* Returns a "take it all over" hello world style request.
*/
function ctools_ajax_sample_hello($js = NULL) {
$output = '<h1>' . t('Hello World') . '</h1>';
if ($js) {
ctools_include('ajax');
$commands = array();
$commands[] = ajax_command_html('#ctools-sample', $output);
print ajax_render($commands); // this function exits.
exit;
}
else {
return $output;
}
}
/**
* Nix a row from a table and restripe.
*/
function ctools_ajax_sample_tablenix($js, $row) {
if (!$js) {
// We don't support degrading this from js because we're not
// using the server to remember the state of the table.
return MENU_ACCESS_DENIED;
}
ctools_include('ajax');
$commands = array();
$commands[] = ajax_command_remove("tr.ajax-sample-row-$row");
$commands[] = ajax_command_restripe("table.ajax-sample-table");
print ajax_render($commands);
exit;
}
/**
* A modal login callback.
*/
function ctools_ajax_sample_login($js = NULL) {
// Fall back if $js is not set.
if (!$js) {
return drupal_get_form('user_login');
}
ctools_include('modal');
ctools_include('ajax');
$form_state = array(
'title' => t('Login'),
'ajax' => TRUE,
);
$output = ctools_modal_form_wrapper('user_login', $form_state);
if (!empty($form_state['executed'])) {
// We'll just overwrite the form output if it was successful.
$output = array();
$inplace = ctools_ajax_text_button(t('remain here'), 'ctools_ajax_sample/nojs/login/inplace', t('Go to your account'));
$account = ctools_ajax_text_button(t('your account'), 'ctools_ajax_sample/nojs/login/user', t('Go to your account'));
$output[] = ctools_modal_command_display(t('Login Success'), '<div class="modal-message">Login successful. You can now choose whether to '. $inplace .', or go to '. $account.'.</div>');
}
print ajax_render($output);
exit;
}
/**
* Post-login processor: should we go to the user account or stay in place?
*/
function ctools_ajax_sample_login_success($js, $action) {
if (!$js) {
// we should never be here out of ajax context
return MENU_NOT_FOUND;
}
ctools_include('ajax');
ctools_add_js('ajax-responder');
$commands = array();
if ($action == 'inplace') {
// stay here
$commands[] = ctools_ajax_command_reload();
}
else {
// bounce bounce
$commands[] = ctools_ajax_command_redirect('user');
}
print ajax_render($commands);
exit;
}
/**
* A modal login callback.
*/
function ctools_ajax_sample_animal($js = NULL, $step = NULL) {
if ($js) {
ctools_include('modal');
ctools_include('ajax');
}
$form_info = array(
'id' => 'animals',
'path' => "ctools_ajax_sample/" . ($js ? 'ajax' : 'nojs') . "/animal/%step",
'show trail' => TRUE,
'show back' => TRUE,
'show cancel' => TRUE,
'show return' => FALSE,
'next callback' => 'ctools_ajax_sample_wizard_next',
'finish callback' => 'ctools_ajax_sample_wizard_finish',
'cancel callback' => 'ctools_ajax_sample_wizard_cancel',
// this controls order, as well as form labels
'order' => array(
'start' => t('Choose animal'),
),
// here we map a step to a form id.
'forms' => array(
// e.g. this for the step at wombat/create
'start' => array(
'form id' => 'ctools_ajax_sample_start'
),
),
);
// We're not using any real storage here, so we're going to set our
// object_id to 1. When using wizard forms, id management turns
// out to be one of the hardest parts. Editing an object with an id
// is easy, but new objects don't usually have ids until somewhere
// in creation.
//
// We skip all this here by just using an id of 1.
$object_id = 1;
if (empty($step)) {
// We reset the form when $step is NULL because that means they have
// for whatever reason started over.
ctools_ajax_sample_cache_clear($object_id);
$step = 'start';
}
// This automatically gets defaults if there wasn't anything saved.
$object = ctools_ajax_sample_cache_get($object_id);
$animals = ctools_ajax_sample_animals();
// Make sure we can't somehow accidentally go to an invalid animal.
if (empty($animals[$object->type])) {
$object->type = 'unknown';
}
// Now that we have our object, dynamically add the animal's form.
if ($object->type == 'unknown') {
// If they haven't selected a type, add a form that doesn't exist yet.
$form_info['order']['unknown'] = t('Configure animal');
$form_info['forms']['unknown'] = array('form id' => 'nothing');
}
else {
// Add the selected animal to the order so that it shows up properly in the trail.
$form_info['order'][$object->type] = $animals[$object->type]['config title'];
}
// Make sure all animals forms are represented so that the next stuff can
// work correctly:
foreach ($animals as $id => $animal) {
$form_info['forms'][$id] = array('form id' => $animals[$id]['form']);
}
$form_state = array(
'ajax' => $js,
// Put our object and ID into the form state cache so we can easily find
// it.
'object_id' => $object_id,
'object' => &$object,
);
// Send this all off to our form. This is like drupal_get_form only wizardy.
ctools_include('wizard');
$form = ctools_wizard_multistep_form($form_info, $step, $form_state);
$output = drupal_render($form);
if ($output === FALSE || !empty($form_state['complete'])) {
// This creates a string based upon the animal and its setting using
// function indirection.
$animal = $animals[$object->type]['output']($object);
}
// If $output is FALSE, there was no actual form.
if ($js) {
// If javascript is active, we have to use a render array.
$commands = array();
if ($output === FALSE || !empty($form_state['complete'])) {
// Dismiss the modal.
$commands[] = ajax_command_html('#ctools-sample', $animal);
$commands[] = ctools_modal_command_dismiss();
}
else if (!empty($form_state['cancel'])) {
// If cancelling, return to the activity.
$commands[] = ctools_modal_command_dismiss();
}
else {
$commands = ctools_modal_form_render($form_state, $output);
}
print ajax_render($commands);
exit;
}
else {
if ($output === FALSE || !empty($form_state['complete'])) {
return $animal;
}
else if (!empty($form_state['cancel'])) {
drupal_goto('ctools_ajax_sample');
}
else {
return $output;
}
}
}
// ---------------------------------------------------------------------------
// Themes
/**
* Theme function for main rendered output.
*/
function theme_ctools_ajax_sample_container($vars) {
$output = '<div id="ctools-sample">';
$output .= $vars['content'];
$output .= '</div>';
return $output;
}
// ---------------------------------------------------------------------------
// Stuff needed for our little wizard.
/**
* Get a list of our animals and associated forms.
*
* What we're doing is making it easy to add more animals in just one place,
* which is often how it will work in the real world. If using CTools, what
* you would probably really have, here, is a set of plugins for each animal.
*/
function ctools_ajax_sample_animals() {
return array(
'sheep' => array(
'title' => t('Sheep'),
'config title' => t('Configure sheep'),
'form' => 'ctools_ajax_sample_configure_sheep',
'output' => 'ctools_ajax_sample_show_sheep',
),
'lizard' => array(
'title' => t('Lizard'),
'config title' => t('Configure lizard'),
'form' => 'ctools_ajax_sample_configure_lizard',
'output' => 'ctools_ajax_sample_show_lizard',
),
'raptor' => array(
'title' => t('Raptor'),
'config title' => t('Configure raptor'),
'form' => 'ctools_ajax_sample_configure_raptor',
'output' => 'ctools_ajax_sample_show_raptor',
),
);
}
// ---------------------------------------------------------------------------
// Wizard caching helpers.
/**
* Store our little cache so that we can retain data from form to form.
*/
function ctools_ajax_sample_cache_set($id, $object) {
ctools_include('object-cache');
ctools_object_cache_set('ctools_ajax_sample', $id, $object);
}
/**
* Get the current object from the cache, or default.
*/
function ctools_ajax_sample_cache_get($id) {
ctools_include('object-cache');
$object = ctools_object_cache_get('ctools_ajax_sample', $id);
if (!$object) {
// Create a default object.
$object = new stdClass;
$object->type = 'unknown';
$object->name = '';
}
return $object;
}
/**
* Clear the wizard cache.
*/
function ctools_ajax_sample_cache_clear($id) {
ctools_include('object-cache');
ctools_object_cache_clear('ctools_ajax_sample', $id);
}
// ---------------------------------------------------------------------------
// Wizard in-between helpers; what to do between or after forms.
/**
* Handle the 'next' click on the add/edit pane form wizard.
*
* All we need to do is store the updated pane in the cache.
*/
function ctools_ajax_sample_wizard_next(&$form_state) {
ctools_ajax_sample_cache_set($form_state['object_id'], $form_state['object']);
}
/**
* Handle the 'finish' click on teh add/edit pane form wizard.
*
* All we need to do is set a flag so the return can handle adding
* the pane.
*/
function ctools_ajax_sample_wizard_finish(&$form_state) {
$form_state['complete'] = TRUE;
}
/**
* Handle the 'cancel' click on the add/edit pane form wizard.
*/
function ctools_ajax_sample_wizard_cancel(&$form_state) {
$form_state['cancel'] = TRUE;
}
// ---------------------------------------------------------------------------
// Wizard forms for our simple info collection wizard.
/**
* Wizard start form. Choose an animal.
*/
function ctools_ajax_sample_start($form, &$form_state) {
$form_state['title'] = t('Choose animal');
$animals = ctools_ajax_sample_animals();
foreach ($animals as $id => $animal) {
$options[$id] = $animal['title'];
}
$form['type'] = array(
'#title' => t('Choose your animal'),
'#type' => 'radios',
'#options' => $options,
'#default_value' => $form_state['object']->type,
'#required' => TRUE,
);
return $form;
}
/**
* They have selected a sheep. Set it.
*/
function ctools_ajax_sample_start_submit(&$form, &$form_state) {
$form_state['object']->type = $form_state['values']['type'];
// Override where to go next based on the animal selected.
$form_state['clicked_button']['#next'] = $form_state['values']['type'];
}
/**
* Wizard form to configure your sheep.
*/
function ctools_ajax_sample_configure_sheep($form, &$form_state) {
$form_state['title'] = t('Configure sheep');
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name your sheep'),
'#default_value' => $form_state['object']->name,
'#required' => TRUE,
);
$form['sheep'] = array(
'#title' => t('What kind of sheep'),
'#type' => 'radios',
'#options' => array(
t('Wensleydale') => t('Wensleydale'),
t('Merino') => t('Merino'),
t('Corriedale') => t('Coriedale'),
),
'#default_value' => !empty($form_state['object']->sheep) ? $form_state['object']->sheep : '',
'#required' => TRUE,
);
return $form;
}
/**
* Submit the sheep and store the values from the form.
*/
function ctools_ajax_sample_configure_sheep_submit(&$form, &$form_state) {
$form_state['object']->name = $form_state['values']['name'];
$form_state['object']->sheep = $form_state['values']['sheep'];
}
/**
* Provide some output for our sheep.
*/
function ctools_ajax_sample_show_sheep($object) {
return t('You have a @type sheep named "@name".', array(
'@type' => $object->sheep,
'@name' => $object->name,
));
}
/**
* Wizard form to configure your lizard.
*/
function ctools_ajax_sample_configure_lizard($form, &$form_state) {
$form_state['title'] = t('Configure lizard');
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name your lizard'),
'#default_value' => $form_state['object']->name,
'#required' => TRUE,
);
$form['lizard'] = array(
'#title' => t('Venomous'),
'#type' => 'checkbox',
'#default_value' => !empty($form_state['object']->lizard),
);
return $form;
}
/**
* Submit the lizard and store the values from the form.
*/
function ctools_ajax_sample_configure_lizard_submit(&$form, &$form_state) {
$form_state['object']->name = $form_state['values']['name'];
$form_state['object']->lizard = $form_state['values']['lizard'];
}
/**
* Provide some output for our raptor.
*/
function ctools_ajax_sample_show_lizard($object) {
return t('You have a @type lizard named "@name".', array(
'@type' => empty($object->lizard) ? t('non-venomous') : t('venomous'),
'@name' => $object->name,
));
}
/**
* Wizard form to configure your raptor.
*/
function ctools_ajax_sample_configure_raptor($form, &$form_state) {
$form_state['title'] = t('Configure raptor');
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name your raptor'),
'#default_value' => $form_state['object']->name,
'#required' => TRUE,
);
$form['raptor'] = array(
'#title' => t('What kind of raptor'),
'#type' => 'radios',
'#options' => array(
t('Eagle') => t('Eagle'),
t('Hawk') => t('Hawk'),
t('Owl') => t('Owl'),
t('Buzzard') => t('Buzzard'),
),
'#default_value' => !empty($form_state['object']->raptor) ? $form_state['object']->raptor : '',
'#required' => TRUE,
);
$form['domesticated'] = array(
'#title' => t('Domesticated'),
'#type' => 'checkbox',
'#default_value' => !empty($form_state['object']->domesticated),
);
return $form;
}
/**
* Submit the raptor and store the values from the form.
*/
function ctools_ajax_sample_configure_raptor_submit(&$form, &$form_state) {
$form_state['object']->name = $form_state['values']['name'];
$form_state['object']->raptor = $form_state['values']['raptor'];
$form_state['object']->domesticated = $form_state['values']['domesticated'];
}
/**
* Provide some output for our raptor.
*/
function ctools_ajax_sample_show_raptor($object) {
return t('You have a @type @raptor named "@name".', array(
'@type' => empty($object->domesticated) ? t('wild') : t('domesticated'),
'@raptor' => $object->raptor,
'@name' => $object->name,
));
}
/**
* Helper function to provide a sample jump menu form
*/
function ctools_ajax_sample_jump_menu_form() {
$url = url('ctools_ajax_sample/jumped');
$form_state = array();
$form = ctools_jump_menu(array(), $form_state, array($url => t('Jump!')), array());
return $form;
}
/**
* Provide a message to the user that the jump menu worked
*/
function ctools_ajax_sample_jump_menu_page() {
$return_link = l(t('Return to the examples page.'), 'ctools_ajax_sample');
$output = t('You successfully jumped! !return_link', array('!return_link' => $return_link));
return $output;
}
/**
* Provide a form for an example ajax modal button
*/
function ctools_ajax_sample_ajax_button_form() {
$form = array();
$form['url'] = array(
'#type' => 'hidden',
// The name of the class is the #id of $form['ajax_button'] with "-url"
// suffix.
'#attributes' => array('class' => array('ctools-ajax-sample-button-url')),
'#value' => url('ctools_ajax_sample/nojs/animal'),
);
$form['ajax_button'] = array(
'#type' => 'button',
'#value' => 'Wizard (button modal)',
'#attributes' => array('class' => array('ctools-use-modal')),
'#id' => 'ctools-ajax-sample-button',
);
return $form;
}