flag_actions.module 22 KB

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