materio_admin.module 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. 'file path' => drupal_get_path('module', 'node'),
  44. 'file' => 'node.pages.inc',
  45. );
  46. }
  47. }
  48. return $items;
  49. }
  50. /**
  51. * Implements hook_menu_alter().
  52. */
  53. function materio_admin_menu_alter(&$items){
  54. // dsm($items, 'menu alter items');
  55. if(isset($items['admin/people'])){
  56. $items['admin/people']['access arguments'] = array('access default users list');
  57. // dsm($items['admin/people']);
  58. }
  59. if(isset($items['admin/people/expiration'])){
  60. $items['admin/people/expiration']['access arguments'] = array('access default UC roles expiration list');
  61. // dsm($items['admin/people/expiration']);
  62. }
  63. # deactivate default home page
  64. $items['node']['access callback'] = FALSE;
  65. // if(isset($items['admin/content/add/simplenews'])){
  66. // delete($items['admin/content/add/simplenews']);
  67. // $cats = simplenews_category_list();
  68. // dsm($cats, 'cats');
  69. // foreach ($cats as $tid => $name) {
  70. // $items['admin/content/add/simplenews/'.$tid]
  71. // }
  72. // }
  73. }
  74. /**
  75. * Implements hook_menu_local_tasks_alter().
  76. */
  77. function materio_admin_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  78. if ($root_path == 'admin/people/simplenews') {
  79. $item = menu_get_item('admin/content/simplenews');
  80. if ($item['access']) {
  81. $item['title'] = 'Go to '.$item['title'];
  82. $data['actions']['output'][] = array(
  83. '#theme' => 'menu_local_task',
  84. '#link' => $item,
  85. );
  86. }
  87. }
  88. if ($root_path == 'admin/content/simplenews') {
  89. $cats = simplenews_category_list();
  90. foreach ($cats as $tid => $name) {
  91. $item = menu_get_item('node/add/simplenews/'.$tid);
  92. $item['title'] = 'Create new '.$name;
  93. if ($item['access']) {
  94. $data['actions']['output'][] = array(
  95. '#theme' => 'menu_local_task',
  96. '#link' => $item,
  97. );
  98. }
  99. }
  100. $item = menu_get_item('admin/people/simplenews');
  101. if ($item['access']) {
  102. $item['title'] = 'Go to '.$item['title'];
  103. $data['actions']['output'][] = array(
  104. '#theme' => 'menu_local_task',
  105. '#link' => $item,
  106. );
  107. }
  108. }
  109. }
  110. /**
  111. * Implements hook_form_alter().
  112. */
  113. function materio_admin_form_simplenews_node_form_alter(&$form, &$form_state, $form_id) {
  114. // dsm($form_id, '$form_id');
  115. // dsm($form_state, '$form_state');
  116. // dsm($form, '$form');
  117. // dsm($_GET, 'GET');
  118. if(!$form['nid']['#value']){
  119. $cats = simplenews_category_list();
  120. $cats_tids = array_keys($cats);
  121. $q = parse_url($_GET['q']);
  122. $cat = array_pop(explode('/', $q['path']));
  123. // dsm($cat, 'cat');
  124. if(in_array($cat, $cats_tids)){
  125. // prepopulate type of news
  126. $form['field_simplenews_term']['und']['#default_value'] = $cat;
  127. $form['field_simplenews_term']['und']['#disabled'] = true;
  128. // change default template regarding type of news
  129. $form['body']['und'][0]['#default_value'] = materio_admin_getSimplenewsNodeBodyTemplate($cat);
  130. }
  131. }else{
  132. $form['field_simplenews_term']['und']['#disabled'] = true;
  133. }
  134. $form['body']['und'][0]['#rows'] = 50;
  135. }
  136. function materio_admin_getSimplenewsNodeBodyTemplate($cat){
  137. return file_get_contents(drupal_get_path('module', 'materio_admin').'/templates/simplenews_'.$cat.'_node.html');
  138. }