materio_admin.module 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * Implements hook_permission().
  4. */
  5. function materio_admin_permission() {
  6. return array(
  7. 'access default users list' => array(
  8. 'title' => t('Access default users list'),
  9. 'description' => t('Access default users list.'),
  10. ),
  11. 'access default UC roles expiration list' => array(
  12. 'title' => t('access default UC roles expiration list'),
  13. 'description' => t('access default UC roles expiration list.'),
  14. ),
  15. );
  16. }
  17. /**
  18. * Implements hook_menu().
  19. */
  20. function materio_admin_menu() {
  21. if(module_exists('simplenews')){
  22. $cats = simplenews_category_list();
  23. dsm($cats, 'cats');
  24. foreach ($cats as $tid => $name) {
  25. // $items['node/%node/simplenews'] = array(
  26. // 'title' => 'Newsletter',
  27. // 'type' => MENU_LOCAL_TASK,
  28. // 'access callback' => 'simplenews_node_tab_access',
  29. // 'access arguments' => array(1),
  30. // 'page callback' => 'simplenews_node_tab_page',
  31. // 'page arguments' => array(1),
  32. // 'context' => MENU_LOCAL_TASK,
  33. // 'file' => 'includes/simplenews.admin.inc',
  34. // 'weight' => 2,
  35. // );
  36. $items['node/add/simplenews/'.$tid] = array(
  37. 'title' => $name,
  38. 'title callback' => 'check_plain',
  39. 'page callback' => 'node_add',
  40. 'page arguments' => array('simplenews'),
  41. 'access callback' => 'node_access',
  42. 'access arguments' => array('create', 'simplenews'),
  43. // 'description' => $type->description,
  44. 'file path' => drupal_get_path('module', 'node'),
  45. 'file' => 'node.pages.inc',
  46. 'options' => array('query'=>array('cat'=>$tid))
  47. );
  48. }
  49. }
  50. return $items;
  51. }
  52. /**
  53. * Implements hook_menu_alter().
  54. */
  55. function materio_admin_menu_alter(&$items){
  56. // dsm($items, 'menu alter items');
  57. if(isset($items['admin/people'])){
  58. $items['admin/people']['access arguments'] = array('access default users list');
  59. // dsm($items['admin/people']);
  60. }
  61. if(isset($items['admin/people/expiration'])){
  62. $items['admin/people/expiration']['access arguments'] = array('access default UC roles expiration list');
  63. // dsm($items['admin/people/expiration']);
  64. }
  65. # deactivate default home page
  66. $items['node']['access callback'] = FALSE;
  67. // if(isset($items['admin/content/add/simplenews'])){
  68. // delete($items['admin/content/add/simplenews']);
  69. // $cats = simplenews_category_list();
  70. // dsm($cats, 'cats');
  71. // foreach ($cats as $tid => $name) {
  72. // $items['admin/content/add/simplenews/'.$tid]
  73. // }
  74. // }
  75. }
  76. /**
  77. * Implements hook_form_alter().
  78. */
  79. function materio_admin_form_simplenews_node_form_alter(&$form, &$form_state, $form_id) {
  80. // dsm($form_id, '$form_id');
  81. // dsm($form_state, '$form_state');
  82. // dsm($form, '$form');
  83. // dsm($_GET, 'GET');
  84. if(!$form['nid']['#value']){
  85. if(isset($_GET['cat'])){
  86. $cat = $_GET['cat'];
  87. // prepopulate type of news
  88. $form['field_simplenews_term']['und']['#default_value'] = $cat;
  89. $form['field_simplenews_term']['und']['#disabled'] = true;
  90. // change default template regarding type of news
  91. $form['body']['und'][0]['#default_value'] = materio_admin_getSimplenewsNodeBodyTemplate($cat);
  92. $form['body']['und'][0]['#rows'] = 50;
  93. }
  94. }else{
  95. $form['field_simplenews_term']['und']['#disabled'] = true;
  96. }
  97. }
  98. function materio_admin_getSimplenewsNodeBodyTemplate($cat){
  99. return file_get_contents(drupal_get_path('module', 'materio_admin').'/templates/simplenews_'.$cat.'_node.html');
  100. }