Create custom token

Public

Custom token code

</> CopyGet raw version
php
  1. /* implements hook_token_info */
  2. function cws_my_account_token_info(){
  3.  
  4. $type['my_account_page'] = array(
  5. 'name' => 'MyAccount',
  6. 'description' => 'Helper function to include content inside body pages'
  7. );
  8.  
  9. $myaccount['overview_cart'] = array(
  10. 'name' => 'Overview Shopping cart ',
  11. 'description' => 'Show the cart content or a link if its empty'
  12. );
  13. $myaccount['overview_subsidy'] = array(
  14. 'name' => 'Subsidy Status',
  15. 'description' => 'Status of the subsidy determinations'
  16. );
  17. $myaccount['applications'] = array(
  18. 'name' => 'Applications',
  19. 'description' => 'Applications, ist iframe'
  20. );
  21. $myaccount['account_profile'] = array(
  22. 'name' => 'Account Profile',
  23. 'description' => 'Account Profile edit, iframe to ist page'
  24. );
  25.  
  26. return array(
  27. 'types' => array('my_account_page' => $type),
  28. 'tokens' => array('my_account_page ' => $myaccount)
  29. );
  30. }
  31.  
  32. /* implements hook_tokens */
  33. function cws_my_account_tokens($type, $tokens, array $data = array(), array $options = array()){
  34. if ($type == 'my_account_page'){
  35. $replacements = array();
  36. foreach ($tokens as $name => $original){
  37. switch ($name){
  38. case 'overview_cart':
  39. $replacements[$original] = _get_shooping_cart();
  40. break;
  41. case 'overview_subsidy':
  42. $replacements[$original] = _overview_subsidy_determination();
  43. break;
  44. case 'applications':
  45. $replacements[$original] = _applications_content();
  46. break;
  47. case 'account_profile':
  48. $replacements[$original] = _account_content();
  49. break;
  50. }
  51. }
  52. return $replacements;
  53. }
  54. }