Projet

Général

Profil

Paste
Télécharger (21,9 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / flag / flag_actions.module @ a5572547

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * Actions support for the Flag module.
6
 */
7
8
/**
9
 * Implements hook_flag_flag(). Trigger actions if any are available.
10
 */
11
function flag_actions_flag_flag($flag, $entity_id, $account, $flagging) {
12
  flag_actions_do('flag', $flag, $entity_id, $account);
13
}
14
15
/**
16
 * Implements hook_flag_unflag(). Trigger actions if any are available.
17
 */
18
function flag_actions_flag_unflag($flag, $entity_id, $account, $flagging) {
19
  flag_actions_do('unflag', $flag, $entity_id, $account);
20
}
21
22
/**
23
 * Implements hook_menu().
24
 */
25
function flag_actions_menu() {
26
  $items = array();
27
28
  $items[FLAG_ADMIN_PATH . '/actions'] = array(
29
    'title' => 'Actions',
30
    'page callback' => 'flag_actions_page',
31
    'access callback' => 'user_access',
32
    'access arguments' => array('administer actions'),
33
    'type' => MENU_LOCAL_TASK,
34
    'weight' => 1,
35
  );
36
  $items[FLAG_ADMIN_PATH . '/actions/add'] = array(
37
    'title' => 'Add action',
38
    'page callback' => 'drupal_get_form',
39
    'page arguments' => array('flag_actions_form', NULL, 5),
40
    'access callback' => 'user_access',
41
    'access arguments' => array('administer actions'),
42
    'type' => MENU_CALLBACK,
43
  );
44
  $items[FLAG_ADMIN_PATH . '/actions/delete'] = array(
45
    'title' => 'Delete action',
46
    'page callback' => 'drupal_get_form',
47
    'page arguments' => array('flag_actions_delete_form', 5),
48
    'access callback' => 'user_access',
49
    'access arguments' => array('administer actions'),
50
    'type' => MENU_CALLBACK,
51
  );
52
  $items[FLAG_ADMIN_PATH . '/actions/configure'] = array(
53
    'title' => 'Edit action',
54
    'page callback' => 'drupal_get_form',
55
    'page arguments' => array('flag_actions_form', 5),
56
    'access callback' => 'user_access',
57
    'access arguments' => array('administer actions'),
58
    'type' => MENU_CALLBACK,
59
  );
60
61
  return $items;
62
}
63
64
/**
65
 * Implements hook_theme().
66
 */
67
function flag_actions_theme() {
68
  return array(
69
    'flag_actions_page' => array(
70
      'variables' => array('actions' => NULL, 'form' => NULL),
71
    ),
72
    'flag_actions_add_form' => array(
73
      'render element' => 'form',
74
    ),
75
    'flag_actions_flag_form' => array(
76
      'render element' => 'form',
77
    ),
78
  );
79
}
80
81
function flag_actions_get_action($aid) {
82
  $actions = flag_actions_get_actions();
83
  return $actions[$aid];
84
}
85
86
function flag_actions_get_actions($flag_name = NULL, $reset = FALSE) {
87
  $flag_actions = &drupal_static(__FUNCTION__);
88
  module_load_include('inc', 'flag', 'includes/flag.actions');
89
90
  // Get a list of all possible actions defined by modules.
91
  $actions = module_invoke_all('action_info');
92
93
  // Retrieve the list of user-defined flag actions.
94
  if (!isset($flag_actions) || $reset) {
95
    $flag_actions = array();
96
    $query = db_select('flag_actions', 'a');
97
    $query->innerJoin('flag', 'f', 'a.fid = f.fid');
98
    $query->addField('f', 'name', 'flag');
99
    $result = $query
100
      ->fields('a')
101
      ->execute();
102
    foreach ($result as $action) {
103
      if (!isset($actions[$action->callback])) {
104
        $actions[$action->callback] = array(
105
          'description' => t('Missing action "@action-callback". Module providing it was either uninstalled or disabled.', array('@action-callback' => $action->callback)),
106
          'configurable' => FALSE,
107
          'type' => 'node',
108
          'missing' => TRUE,
109
        );
110
      }
111
      $action->parameters = unserialize($action->parameters);
112
      $action->label = $actions[$action->callback]['label'];
113
      $action->configurable = $actions[$action->callback]['configurable'];
114
      $action->behavior = isset($actions[$action->callback]['behavior']) ? $actions[$action->callback]['behavior'] : array();
115
      $action->type = $actions[$action->callback]['type'];
116
      $action->missing = !empty($actions[$action->callback]['missing']);
117
118
      $flag_actions[$action->aid] = $action;
119
    }
120
  }
121
122
  // Filter actions to a specified flag.
123
  if (isset($flag_name)) {
124
    $specific_flag_actions = array();
125
    foreach ($flag_actions as $aid => $action) {
126
      if ($action->flag == $flag_name) {
127
        $specific_flag_actions[$aid] = $action;
128
      }
129
    }
130
    return $specific_flag_actions;
131
  }
132
133
  return $flag_actions;
134
}
135
136
/**
137
 * Insert a new flag action.
138
 *
139
 * @param $fid
140
 *   The flag object ID.
141
 * @param $event
142
 *   The flag event, such as "flag" or "unflag".
143
 * @param $threshold
144
 *   The flagging threshold at which this action will be executed.
145
 * @param $repeat_threshold
146
 *   The number of additional flaggings after which the action will be repeated.
147
 * @param $callback
148
 *   The action callback to be executed.
149
 * @param $parameters
150
 *   The action parameters.
151
 */
152
function flag_actions_insert_action($fid, $event, $threshold, $repeat_threshold, $callback, $parameters) {
153
  return db_insert('flag_actions')
154
    ->fields(array(
155
      'fid' => $fid,
156
      'event' => $event,
157
      'threshold' => $threshold,
158
      'repeat_threshold' => $repeat_threshold,
159
      'callback' => $callback,
160
      'parameters' => serialize($parameters),
161
    ))
162
    ->execute();
163
}
164
165
/**
166
 * Update an existing flag action.
167
 *
168
 * @param $aid
169
 *   The flag action ID to update.
170
 * @param $event
171
 *   The flag event, such as "flag" or "unflag".
172
 * @param $threshold
173
 *   The flagging threshold at which this action will be executed.
174
 * @param $repeat_threshold
175
 *   The number of additional flaggings after which the action will be repeated.
176
 * @param $parameters
177
 *   The action parameters.
178
 */
179
function flag_actions_update_action($aid, $event, $threshold, $repeat_threshold, $parameters) {
180
  return db_update('flag_actions')
181
    ->fields(array(
182
      'event' => $event,
183
      'threshold' => $threshold,
184
      'repeat_threshold' => $repeat_threshold,
185
      'parameters' => serialize($parameters),
186
    ))
187
    ->condition('aid', $aid)
188
    ->execute();
189
}
190
191
/**
192
 * Delete a flag action.
193
 *
194
 * @param $aid
195
 *   The flag action ID to delete.
196
 */
197
function flag_actions_delete_action($aid) {
198
  return db_delete('flag_actions', array('return' => Database::RETURN_AFFECTED))
199
    ->condition('aid', $aid)
200
    ->execute();
201
}
202
203
/**
204
 * Perform flag actions.
205
 */
206
function flag_actions_do($event, $flag, $entity_id, $account) {
207
  $actions = flag_actions_get_actions($flag->name);
208
  if (!$actions) {
209
    return;
210
  }
211
212
  $flag_action = $flag->get_flag_action($entity_id);
213
  $flag_action->action = $event;
214
  $flag_action->count = $count = $flag->get_count($entity_id);
215
  $relevant_objects = $flag->get_relevant_action_objects($entity_id);
216
  $object_changed = FALSE;
217
  foreach ($actions as $aid => $action) {
218
    if ($action->event == 'flag') {
219
      $at_threshold = ($count == $action->threshold);
220
      $repeat = $action->repeat_threshold ? (($count > $action->threshold) && (($count - $action->threshold) % $action->repeat_threshold == 0)) : FALSE;
221
    }
222
    elseif ($action->event == 'unflag') {
223
      $at_threshold = ($count == $action->threshold - 1);
224
      $repeat = $action->repeat_threshold ? (($count < $action->threshold - 1) && (($count - $action->threshold - 1) % $action->repeat_threshold == 0)) : FALSE;
225
    }
226
    if (($at_threshold || $repeat) && $action->event == $event && !$action->missing) {
227
      $context = $action->parameters;
228
      $context['callback'] = $action->callback;
229
      // We're setting 'hook' to something, to prevent PHP warnings by actions
230
      // who read it. Maybe we should set it to nodeapi/comment/user, depending
231
      // on the flag, because these three are among the only hooks some actions
232
      // in system.module "know" to work with.
233
      $context['hook'] = 'flag';
234
      $context['type'] = $action->type;
235
      $context['account'] = $account;
236
      $context['flag'] = $flag;
237
      $context['flag-action'] = $flag_action;
238
      // We add to the $context all the objects we know about:
239
      $context = array_merge($relevant_objects, $context);
240
      $callback = $action->callback;
241
242
      if (isset($relevant_objects[$action->type])) {
243
        $callback($relevant_objects[$action->type], $context);
244
      }
245
      else {
246
        // What object shall we send as last resort? Let's send a node, or
247
        // the flag's object.
248
        if (isset($relevant_objects['node'])) {
249
          $callback($relevant_objects['node'], $context);
250
        }
251
        else {
252
          $callback($relevant_objects[$flag->entity_type], $context);
253
        }
254
      }
255
256
      if (is_array($action->behavior) && in_array('changes_property', $action->behavior)) {
257
        $object_changed = TRUE;
258
      }
259
    }
260
  }
261
262
  // Actions by default do not save elements unless the save action is
263
  // explicitly added. We run it automatically upon flagging.
264
  if ($object_changed) {
265
    $save_action = $action->type . '_save_action';
266
    if (function_exists($save_action)) {
267
      $save_action($relevant_objects[$action->type]);
268
    }
269
  }
270
}
271
272
/**
273
 * Menu callback for FLAG_ADMIN_PATH/actions.
274
 */
275
function flag_actions_page() {
276
  $actions = flag_actions_get_actions();
277
  $add_action_form = drupal_get_form('flag_actions_add_form');
278
279
  return theme('flag_actions_page', array('actions' => $actions, 'form' => $add_action_form));
280
}
281
282
/**
283
 * Theme the list of actions currently in place for flags.
284
 */
285
function theme_flag_actions_page($variables) {
286
  $actions = $variables['actions'];
287
  $add_action_form = $variables['form'];
288
289
  $rows = array();
290
  foreach ($actions as $action) {
291
    $flag = flag_get_flag($action->flag);
292
293
    // Build a sample string representing repeating actions.
294
    if ($action->repeat_threshold) {
295
      $repeat_count = 3;
296
      $repeat_subtract = ($action->event == 'flag') ? 1 : -1;
297
      $repeat_samples = array();
298
      for ($n = 1; $n < $repeat_count + 2; $n++) {
299
        $sample = $action->threshold + (($n * $action->repeat_threshold) * $repeat_subtract);
300
        if ($sample > 0) {
301
          $repeat_samples[] = $sample;
302
        }
303
      }
304
      if (count($repeat_samples) > $repeat_count) {
305
        $repeat_samples[$repeat_count] = '&hellip;';
306
      }
307
      $repeat_string = implode(', ', $repeat_samples);
308
    }
309
    else {
310
      $repeat_string = '-';
311
    }
312
313
    $row = array();
314
    $row[] = $flag->get_title();
315
    $row[] = ($action->event == 'flag' ? '&ge; ' : '&lt; ') . $action->threshold;
316
    $row[] = $repeat_string;
317
    $row[] = empty($action->missing) ? $action->label : '<div class="error">' . $action->label . '</div>';
318
    $row[] = l(t('edit'), FLAG_ADMIN_PATH . '/actions/configure/' . $action->aid);
319
    $row[] = l(t('delete'), FLAG_ADMIN_PATH . '/actions/delete/' . $action->aid);
320
    $rows[] = $row;
321
  }
322
323
  if (empty($rows)) {
324
    $rows[] = array(array('data' => t('Currently no flag actions. Use the <em>Add new flag action</em> form to add an action.'), 'colspan' => 6));
325
  }
326
327
  $header = array(
328
    t('Flag'),
329
    t('Threshold'),
330
    t('Repeats'),
331
    t('Action'),
332
    array('data' => t('Operations'), 'colspan' => 2),
333
  );
334
335
  $output = '';
336
  $output .= theme('table', array('header' => $header, 'rows' => $rows));
337
  $output .= drupal_render($add_action_form);
338
  return $output;
339
}
340
341
/**
342
 * Modified version of the Add action form that redirects back to the flag list.
343
 */
344
function flag_actions_add_form($form, &$form_state) {
345
  $flags = flag_get_flags();
346
  $options = array();
347
  foreach ($flags as $flag) {
348
    $options[$flag->name] = $flag->get_title();
349
  }
350
351
  if (empty($options)) {
352
    $options[] = t('No flag available');
353
  }
354
355
  $form['flag'] = array(
356
    '#type' => 'select',
357
    '#options' => empty($options) ? array(t('No flag available')) : $options,
358
    '#disabled' => empty($options),
359
    '#title' => t('Select a flag'),
360
  );
361
362
  $form['submit'] = array(
363
    '#type' => 'submit',
364
    '#value' => t('Add action'),
365
  );
366
367
  return $form;
368
}
369
370
function flag_actions_add_form_submit($form, &$form_state) {
371
  if ($form_state['values']['flag']) {
372
    $form_state['redirect'] = array(FLAG_ADMIN_PATH . '/actions/add/' . $form_state['values']['flag']);
373
  }
374
}
375
376
function theme_flag_actions_add_form($variables) {
377
  $form = $variables['form'];
378
379
  $fieldset = array(
380
    '#type' => 'fieldset',
381
    '#title' => t('Add a new flag action'),
382
    '#children' => '<div class="container-inline">'. drupal_render($form['flag']) . drupal_render($form['submit']) .'</div>',
383
    '#parents' => array('add_action'),
384
    '#attributes' => array(),
385
    '#groups' => array('add_action' => array()),
386
  );
387
388
  return drupal_render($fieldset) . drupal_render_children($form);
389
}
390
391
/**
392
 * Generic configuration form for configuration of flag actions.
393
 *
394
 * @param $form_state
395
 *   The form state.
396
 * @param $aid
397
 *   If editing an action, an action ID must be passed in.
398
 * @param $flag_name
399
 *   If adding a new action to a flag, a flag name must be specified.
400
 *
401
 */
402
function flag_actions_form($form, &$form_state, $aid = NULL, $flag_name = NULL) {
403
  // This is a multistep form. Get the callback value if set and continue.
404
  if (isset($form_state['storage']['callback'])) {
405
    $callback = $form_state['storage']['callback'];
406
    unset($form_state['storage']['callback']);
407
  }
408
409
  if (isset($aid)) {
410
    $action = flag_actions_get_action($aid);
411
    $callback = $action->callback;
412
    $flag = flag_get_flag($action->flag);
413
    drupal_set_title(t('Edit the "@action" action for the @title flag', array('@action' => $action->label, '@title' => $flag->get_title())));
414
  }
415
  elseif (isset($flag_name)) {
416
    $flag = flag_get_flag($flag_name);
417
  }
418
419
  if (empty($flag)) {
420
    drupal_not_found();
421
  }
422
423
  $form['new'] = array(
424
    '#type' => 'value',
425
    '#value' => isset($callback) ? FALSE: TRUE,
426
  );
427
428
  if (!isset($callback)) {
429
    drupal_set_title(t('Add an action to the @title flag', array('@title' => $flag->get_title())));
430
431
    $actions = $flag->get_valid_actions();
432
    $options = array();
433
    foreach($actions as $key => $action) {
434
      $options[$key] = $action['label'];
435
    }
436
437
    $form['callback'] = array(
438
      '#title' => t('Select an action'),
439
      '#type' => 'select',
440
      '#options' => $options,
441
    );
442
443
    $form['submit'] = array(
444
      '#type' => 'submit',
445
      '#value' => t('Continue'),
446
    );
447
448
    return $form;
449
  }
450
  elseif (!isset($action)) {
451
    $actions = $flag->get_valid_actions();
452
    $action = (object)$actions[$callback];
453
    $action->parameters = array();
454
    $action->event = 'flag';
455
    $action->threshold = 10;
456
    $action->repeat_threshold = 0;
457
    drupal_set_title(t('Add "@action" action to the @title flag', array('@action' => $action->label, '@title' => $flag->get_title())));
458
  }
459
460
  $form['flag'] = array(
461
    '#tree' => TRUE,
462
    '#weight' => -9,
463
    '#theme' => 'flag_actions_flag_form',
464
    '#action' => $action,
465
    '#flag' => $flag,
466
  );
467
468
  $form['flag']['flag'] = array(
469
    '#type' => 'value',
470
    '#value' => $flag,
471
  );
472
473
  $form['flag']['callback'] = array(
474
    '#type' => 'value',
475
    '#value' => $callback,
476
  );
477
478
  $form['flag']['aid'] = array(
479
    '#type' => 'value',
480
    '#value' => $aid,
481
  );
482
483
  $form['flag']['event'] = array(
484
    '#type' => 'select',
485
    '#options' => array(
486
      'flag' => t('reaches'),
487
      'unflag' => t('falls below'),
488
    ),
489
    '#default_value' => $action->event,
490
  );
491
492
  $form['flag']['threshold'] = array(
493
    '#type' => 'textfield',
494
    '#size' => 6,
495
    '#maxlength' => 6,
496
    '#default_value' => $action->threshold,
497
    '#required' => TRUE,
498
  );
499
500
  $form['flag']['repeat_threshold'] = array(
501
    '#type' => 'textfield',
502
    '#size' => 6,
503
    '#maxlength' => 6,
504
    '#default_value' => $action->repeat_threshold,
505
  );
506
507
  if ($flag->global) {
508
    $form['flag']['threshold']['#disabled'] = 1;
509
    $form['flag']['threshold']['#value'] = 1;
510
    $form['flag']['repeat_threshold']['#access'] = FALSE;
511
    $form['flag']['repeat_threshold']['#value'] = 0;
512
  }
513
514
  // Merge in the standard flag action form.
515
  $action_form = $callback .'_form';
516
  $edit = array();
517
  if (function_exists($action_form)) {
518
    $edit += $action->parameters;
519
    $edit['actions_label'] = $action->label;
520
    $edit['actions_type'] = $action->type;
521
    $edit['actions_flag'] = $flag->name;
522
    $additions = flag_actions_form_additions($action_form, $edit);
523
    $form = array_merge($form, $additions);
524
  }
525
526
  // Add a few customizations to existing flag actions.
527
  $flag_actions_form = 'flag_actions_'. $callback .'_form';
528
  if (function_exists($flag_actions_form)) {
529
    $flag_actions_form($form, $flag, $edit);
530
  }
531
532
  $form['submit'] = array(
533
    '#type' => 'submit',
534
    '#value' => t('Submit'),
535
  );
536
537
  return $form;
538
}
539
540
/**
541
 * Execute an action form callback to retrieve form additions.
542
 *
543
 * This function prevents the form callback from modifying local variables.
544
 */
545
function flag_actions_form_additions($callback, $edit) {
546
  return $callback($edit);
547
}
548
549
/**
550
 * Generic submit handler for validating flag actions.
551
 */
552
function flag_actions_form_validate($form, &$form_state) {
553
  // Special validation handlers may be needed to save this form properly.
554
  // Try to load the action's validation routine if needed.
555
  if (isset($form_state['values']['flag']['callback'])) {
556
    $callback = $form_state['values']['flag']['callback'];
557
    $validate_function = $callback . '_validate';
558
    if (function_exists($validate_function)) {
559
      $validate_function($form, $form_state);
560
    }
561
  }
562
}
563
564
/**
565
 * Generic submit handler for saving flag actions.
566
 */
567
function flag_actions_form_submit($form, &$form_state) {
568
  // If simply gathering the callback, save it to form state storage and
569
  // rebuild the form to gather the complete information.
570
  if ($form_state['values']['new']) {
571
    $form_state['storage']['callback'] = $form_state['values']['callback'];
572
    $form_state['rebuild'] = TRUE;
573
    return;
574
  }
575
576
  $aid              = $form_state['values']['flag']['aid'];
577
  $flag             = $form_state['values']['flag']['flag'];
578
  $event            = $form_state['values']['flag']['event'];
579
  $threshold        = $form_state['values']['flag']['threshold'];
580
  $repeat_threshold = $form_state['values']['flag']['repeat_threshold'];
581
  $callback         = $form_state['values']['flag']['callback'];
582
583
  // Specialized forms may need to execute their own submit handlers on save.
584
  $submit_function = $callback . '_submit';
585
  $parameters = function_exists($submit_function) ? $submit_function($form, $form_state) : array();
586
587
  if (empty($aid)) {
588
    $aid = flag_actions_insert_action($flag->fid, $event, $threshold, $repeat_threshold, $callback, $parameters);
589
    $form_state['values']['flag']['aid'] = $aid;
590
    $form_state['values']['flag']['is_new'] = TRUE;
591
  }
592
  else {
593
    flag_actions_update_action($aid, $event, $threshold, $repeat_threshold, $parameters);
594
  }
595
596
  $action = flag_actions_get_action($aid);
597
598
  drupal_set_message(t('The "@action" action for the @title flag has been saved.', array('@action' => $action->label, '@title' => $flag->get_title())));
599
  $form_state['redirect'] = FLAG_ADMIN_PATH . '/actions';
600
}
601
602
function theme_flag_actions_flag_form($variables) {
603
  $form = $variables['form'];
604
605
  $event = drupal_render($form['event']);
606
  $threshold = drupal_render($form['threshold']);
607
  $repeat_threshold = drupal_render($form['repeat_threshold']);
608
  $action = $form['#action']->label;
609
610
  $output  = '';
611
  $output .= '<div class="container-inline">';
612
  $output .= t('Perform action when content !event !threshold flags', array('!event' => $event, '!threshold' => $threshold));
613
  if ($form['#flag']->global) {
614
    $output .= ' ' . t('(global flags always have a threshold of 1)');
615
  }
616
  $output .= '</div>';
617
  $output .= '<div class="container-inline">';
618
  if (!$form['#flag']->global) {
619
    $output .= t('Repeat this action every !repeat_threshold additional flags after the threshold is reached', array('!repeat_threshold' => $repeat_threshold));
620
  }
621
  $output .= '</div>';
622
623
  $element = array(
624
    '#title' => t('Flagging threshold'),
625
    '#required' => TRUE,
626
  );
627
628
  return $output . drupal_render_children($form);
629
}
630
631
function flag_actions_delete_form($form, &$form_state, $aid) {
632
  $action = flag_actions_get_action($aid);
633
  $flag = flag_get_flag($action->flag);
634
635
  $form['action'] = array(
636
    '#type' => 'value',
637
    '#value' => $action,
638
  );
639
640
  $form['flag'] = array(
641
    '#type' => 'value',
642
    '#value' => $flag,
643
  );
644
645
  $question = t('Delete the "@action" action for the @title flag?', array('@action' => $action->label, '@title' => $flag->get_title()));
646
  $path = FLAG_ADMIN_PATH . '/actions';
647
648
  return confirm_form($form, $question, $path, NULL, t('Delete'));
649
}
650
651
function flag_actions_delete_form_submit(&$form, &$form_state) {
652
  flag_actions_delete_action($form_state['values']['action']->aid);
653
  drupal_set_message(t('The "@action" action for the @title flag has been deleted.', array('@action' => $form_state['values']['action']->label, '@title' => $form_state['values']['flag']->get_title())));
654
  $form_state['redirect'] = FLAG_ADMIN_PATH . '/actions';
655
}
656
657
/**
658
 * Make modifications to the "Send e-mail" action form.
659
 */
660
function flag_actions_system_send_email_action_form(&$form, &$flag, $context) {
661
  if (!isset($context['recipient'])) {
662
    $form['recipient']['#default_value'] = '[site:mail]';
663
  }
664
665
  if (!isset($context['subject'])) {
666
    $form['subject']['#default_value'] = t('Content Flagged @flag_title', array('@flag_title' => $flag->get_title()));
667
  }
668
669
  if (!isset($context['message'])) {
670
    $form['message']['#default_value'] = t("The @flag_entity_type [flag-action:content-title] has been flagged [flag-action:count] times with the @flag_title flag.\n\nView this @flag_entity_type at [flag-action:content-url].", array('@flag_entity_type' => $flag->entity_type, '@flag_title' => $flag->get_title()));
671
  }
672
673
  $form['help'] = array(
674
    '#type' => 'fieldset',
675
    '#title' => t('Tokens'),
676
    '#description' => t('The following tokens can be used in the recipient, subject, or message.'),
677
    '#collapsible' => TRUE,
678
    '#collapsed' => TRUE,
679
  );
680
  $form['help']['basic'] = array(
681
    '#markup' => theme('flag_tokens_browser', array('types' => array('flag', 'flag-action'))),
682
  );
683
684
  $form['help']['tokens'] = array(
685
    '#type' => 'fieldset',
686
    '#title' => t('More tokens'),
687
    '#description' => t("Depending on the type of the content being flagged, the following tokens can be used in the recipients, subject, or message. For example, if the content being flagged is a node, you can use any of the node tokens --but you can't use the comment tokens: they won't be recognized. Similarly, if the content being flagged is a user, you can use only the user tokens."),
688
    '#value' => theme('flag_tokens_browser', array('types' => $flag->get_labels_token_types(), 'global_types' => FALSE)),
689
    '#collapsible' => TRUE,
690
    '#collapsed' => TRUE,
691
  );
692
}