flag_actions.module 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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 int $fid
  125. * The flag object ID.
  126. * @param string $event
  127. * The flag event, such as "flag" or "unflag".
  128. * @param int $threshold
  129. * The flagging threshold at which this action will be executed.
  130. * @param int $repeat_threshold
  131. * The number of additional flaggings after which the action will be repeated.
  132. * @param string $callback
  133. * The action callback to be executed.
  134. * @param array $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 int $aid
  153. * The flag action ID to update.
  154. * @param string $event
  155. * The flag event, such as "flag" or "unflag".
  156. * @param int $threshold
  157. * The flagging threshold at which this action will be executed.
  158. * @param int $repeat_threshold
  159. * The number of additional flaggings after which the action will be repeated.
  160. * @param array $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 int $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 int|NULL $aid
  356. * If editing an action, an action ID must be passed in.
  357. * @param string|NULL $flag_name
  358. * If adding a new action to a flag, a flag name must be specified.
  359. */
  360. function flag_actions_form($form, &$form_state, $aid = NULL, $flag_name = NULL) {
  361. // This is a multistep form. Get the callback value if set and continue.
  362. if (isset($form_state['storage']['callback'])) {
  363. $callback = $form_state['storage']['callback'];
  364. unset($form_state['storage']['callback']);
  365. }
  366. if (isset($aid)) {
  367. $action = flag_actions_get_action($aid);
  368. $callback = $action->callback;
  369. $flag = flag_get_flag($action->flag);
  370. drupal_set_title(t('Edit the "@action" action for the @title flag', array('@action' => $action->label, '@title' => $flag->get_title())));
  371. }
  372. elseif (isset($flag_name)) {
  373. $flag = flag_get_flag($flag_name);
  374. }
  375. if (empty($flag)) {
  376. drupal_not_found();
  377. }
  378. $form['new'] = array(
  379. '#type' => 'value',
  380. '#value' => isset($callback) ? FALSE : TRUE,
  381. );
  382. if (!isset($callback)) {
  383. drupal_set_title(t('Add an action to the @title flag', array('@title' => $flag->get_title())));
  384. $actions = $flag->get_valid_actions();
  385. $options = array();
  386. foreach ($actions as $key => $action) {
  387. $options[$key] = $action['label'];
  388. }
  389. $form['callback'] = array(
  390. '#title' => t('Select an action'),
  391. '#type' => 'select',
  392. '#options' => $options,
  393. );
  394. $form['submit'] = array(
  395. '#type' => 'submit',
  396. '#value' => t('Continue'),
  397. );
  398. return $form;
  399. }
  400. elseif (!isset($action)) {
  401. $actions = $flag->get_valid_actions();
  402. $action = (object) $actions[$callback];
  403. $action->parameters = array();
  404. $action->event = 'flag';
  405. $action->threshold = 10;
  406. $action->repeat_threshold = 0;
  407. drupal_set_title(t('Add "@action" action to the @title flag', array('@action' => $action->label, '@title' => $flag->get_title())));
  408. }
  409. $form['flag'] = array(
  410. '#tree' => TRUE,
  411. '#weight' => -9,
  412. '#theme' => 'flag_actions_flag_form',
  413. '#action' => $action,
  414. '#flag' => $flag,
  415. );
  416. $form['flag']['flag'] = array(
  417. '#type' => 'value',
  418. '#value' => $flag,
  419. );
  420. $form['flag']['callback'] = array(
  421. '#type' => 'value',
  422. '#value' => $callback,
  423. );
  424. $form['flag']['aid'] = array(
  425. '#type' => 'value',
  426. '#value' => $aid,
  427. );
  428. $form['flag']['event'] = array(
  429. '#type' => 'select',
  430. '#options' => array(
  431. 'flag' => t('reaches'),
  432. 'unflag' => t('falls below'),
  433. ),
  434. '#default_value' => $action->event,
  435. );
  436. $form['flag']['threshold'] = array(
  437. '#type' => 'textfield',
  438. '#size' => 6,
  439. '#maxlength' => 6,
  440. '#default_value' => $action->threshold,
  441. '#required' => TRUE,
  442. );
  443. $form['flag']['repeat_threshold'] = array(
  444. '#type' => 'textfield',
  445. '#size' => 6,
  446. '#maxlength' => 6,
  447. '#default_value' => $action->repeat_threshold,
  448. );
  449. if ($flag->global) {
  450. $form['flag']['threshold']['#disabled'] = 1;
  451. $form['flag']['threshold']['#value'] = 1;
  452. $form['flag']['repeat_threshold']['#access'] = FALSE;
  453. $form['flag']['repeat_threshold']['#value'] = 0;
  454. }
  455. // Merge in the standard flag action form.
  456. $action_form = $callback . '_form';
  457. $edit = array();
  458. if (function_exists($action_form)) {
  459. $edit += $action->parameters;
  460. $edit['actions_label'] = $action->label;
  461. $edit['actions_type'] = $action->type;
  462. $edit['actions_flag'] = $flag->name;
  463. $additions = flag_actions_form_additions($action_form, $edit);
  464. $form = array_merge($form, $additions);
  465. }
  466. // Add a few customizations to existing flag actions.
  467. $flag_actions_form = 'flag_actions_' . $callback . '_form';
  468. if (function_exists($flag_actions_form)) {
  469. $flag_actions_form($form, $flag, $edit);
  470. }
  471. $form['submit'] = array(
  472. '#type' => 'submit',
  473. '#value' => t('Submit'),
  474. );
  475. return $form;
  476. }
  477. /**
  478. * Execute an action form callback to retrieve form additions.
  479. *
  480. * This function prevents the form callback from modifying local variables.
  481. */
  482. function flag_actions_form_additions($callback, $edit) {
  483. return $callback($edit);
  484. }
  485. /**
  486. * Generic submit handler for validating flag actions.
  487. */
  488. function flag_actions_form_validate($form, &$form_state) {
  489. // Special validation handlers may be needed to save this form properly.
  490. // Try to load the action's validation routine if needed.
  491. if (isset($form_state['values']['flag']['callback'])) {
  492. $callback = $form_state['values']['flag']['callback'];
  493. $validate_function = $callback . '_validate';
  494. if (function_exists($validate_function)) {
  495. $validate_function($form, $form_state);
  496. }
  497. }
  498. }
  499. /**
  500. * Generic submit handler for saving flag actions.
  501. */
  502. function flag_actions_form_submit($form, &$form_state) {
  503. // If simply gathering the callback, save it to form state storage and
  504. // rebuild the form to gather the complete information.
  505. if ($form_state['values']['new']) {
  506. $form_state['storage']['callback'] = $form_state['values']['callback'];
  507. $form_state['rebuild'] = TRUE;
  508. return;
  509. }
  510. $aid = $form_state['values']['flag']['aid'];
  511. $flag = $form_state['values']['flag']['flag'];
  512. $event = $form_state['values']['flag']['event'];
  513. $threshold = $form_state['values']['flag']['threshold'];
  514. $repeat_threshold = $form_state['values']['flag']['repeat_threshold'];
  515. $callback = $form_state['values']['flag']['callback'];
  516. // Specialized forms may need to execute their own submit handlers on save.
  517. $submit_function = $callback . '_submit';
  518. $parameters = function_exists($submit_function) ? $submit_function($form, $form_state) : array();
  519. if (empty($aid)) {
  520. $aid = flag_actions_insert_action($flag->fid, $event, $threshold, $repeat_threshold, $callback, $parameters);
  521. $form_state['values']['flag']['aid'] = $aid;
  522. $form_state['values']['flag']['is_new'] = TRUE;
  523. }
  524. else {
  525. flag_actions_update_action($aid, $event, $threshold, $repeat_threshold, $parameters);
  526. }
  527. $action = flag_actions_get_action($aid);
  528. drupal_set_message(t('The "@action" action for the @title flag has been saved.', array('@action' => $action->label, '@title' => $flag->get_title())));
  529. $form_state['redirect'] = FLAG_ADMIN_PATH . '/actions';
  530. }
  531. function theme_flag_actions_flag_form($variables) {
  532. $form = $variables['form'];
  533. $event = drupal_render($form['event']);
  534. $threshold = drupal_render($form['threshold']);
  535. $repeat_threshold = drupal_render($form['repeat_threshold']);
  536. $action = $form['#action']->label;
  537. $output = '';
  538. $output .= '<div class="container-inline">';
  539. $output .= t('Perform action when content !event !threshold flags', array('!event' => $event, '!threshold' => $threshold));
  540. if ($form['#flag']->global) {
  541. $output .= ' ' . t('(global flags always have a threshold of 1)');
  542. }
  543. $output .= '</div>';
  544. $output .= '<div class="container-inline">';
  545. if (!$form['#flag']->global) {
  546. $output .= t('Repeat this action every !repeat_threshold additional flags after the threshold is reached', array('!repeat_threshold' => $repeat_threshold));
  547. }
  548. $output .= '</div>';
  549. $element = array(
  550. '#title' => t('Flagging threshold'),
  551. '#required' => TRUE,
  552. );
  553. return $output . drupal_render_children($form);
  554. }
  555. function flag_actions_delete_form($form, &$form_state, $aid) {
  556. $action = flag_actions_get_action($aid);
  557. $flag = flag_get_flag($action->flag);
  558. $form['action'] = array(
  559. '#type' => 'value',
  560. '#value' => $action,
  561. );
  562. $form['flag'] = array(
  563. '#type' => 'value',
  564. '#value' => $flag,
  565. );
  566. $question = t('Delete the "@action" action for the @title flag?', array('@action' => $action->label, '@title' => $flag->get_title()));
  567. $path = FLAG_ADMIN_PATH . '/actions';
  568. return confirm_form($form, $question, $path, NULL, t('Delete'));
  569. }
  570. function flag_actions_delete_form_submit(&$form, &$form_state) {
  571. flag_actions_delete_action($form_state['values']['action']->aid);
  572. 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())));
  573. $form_state['redirect'] = FLAG_ADMIN_PATH . '/actions';
  574. }
  575. /**
  576. * Make modifications to the "Send e-mail" action form.
  577. */
  578. function flag_actions_system_send_email_action_form(&$form, &$flag, $context) {
  579. if (!isset($context['recipient'])) {
  580. $form['recipient']['#default_value'] = '[site:mail]';
  581. }
  582. if (!isset($context['subject'])) {
  583. $form['subject']['#default_value'] = t('Content Flagged @flag_title', array('@flag_title' => $flag->get_title()));
  584. }
  585. if (!isset($context['message'])) {
  586. $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()));
  587. }
  588. $form['help'] = array(
  589. '#type' => 'fieldset',
  590. '#title' => t('Tokens'),
  591. '#description' => t('The following tokens can be used in the recipient, subject, or message.'),
  592. '#collapsible' => TRUE,
  593. '#collapsed' => TRUE,
  594. );
  595. $form['help']['basic'] = array(
  596. '#markup' => theme('flag_tokens_browser', array('types' => array('flag', 'flag-action'))),
  597. );
  598. $form['help']['tokens'] = array(
  599. '#type' => 'fieldset',
  600. '#title' => t('More tokens'),
  601. '#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."),
  602. '#value' => theme('flag_tokens_browser', array('types' => $flag->get_labels_token_types(), 'global_types' => FALSE)),
  603. '#collapsible' => TRUE,
  604. '#collapsed' => TRUE,
  605. );
  606. }