materio_personalnotes.module 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Implements hook_init().
  4. */
  5. function materio_personalnotes_init() {
  6. drupal_add_js(drupal_get_path('module', 'materio_personalnotes').'/js/materio_personalnotes.js');
  7. }
  8. /**
  9. * Implements hook_permission().
  10. */
  11. function materio_personalnotes_permission() {
  12. $perms = array(
  13. 'create own personal notes' => array(
  14. 'title' => t('Create own personal notes'),
  15. 'description' => t('Create own personal notes'),
  16. ),
  17. );
  18. return $perms;
  19. }
  20. // function materio_personalnotes_menu(){
  21. // $items = array();
  22. //
  23. // $base = array(
  24. // 'type' => MENU_CALLBACK,
  25. // 'file' => 'materio_personalnotes.pages.inc',
  26. // );
  27. //
  28. // $items['materio_personalnotes/registerblock'] = $base+array(
  29. // 'title' => 'Materio base user ajax',
  30. // 'page callback' => 'materio_personalnotes_registerblock',
  31. // // 'page arguments' => array(),
  32. // 'access callback' => TRUE,
  33. // );
  34. //
  35. // return $items;
  36. // }
  37. /**
  38. * Implements hook_menu_alter().
  39. */
  40. // function materio_personalnotes_menu_alter(&$items) {
  41. // $items['user/%user']['access callback'] = 'user_access';
  42. // $items['user/%user']['access arguments'] = array('view own user profile');
  43. // }
  44. /**
  45. * Implements hook_entity_view().
  46. *
  47. * Note this is broken for taxonomy terms. @see http://drupal.org/node/1067120
  48. */
  49. function materio_personalnotes_entity_view($entity, $type, $view_mode, $langcode) {
  50. if($type == 'node'){
  51. if(user_access('create own personal notes') && $view_mode != 'print'){
  52. $entity->content['personalnotelink'] = materio_personalnotes_get_note_link($entity);
  53. // drupal_add_css(drupal_get_path('module', 'flag') . '/theme/flag.css');
  54. // drupal_add_js(drupal_get_path('module', 'flag') . '/theme/flag.js');
  55. }
  56. }
  57. }
  58. function materio_personalnotes_get_note_link($entity){
  59. // if note alredy exists link to it
  60. // else create one
  61. #create new list
  62. $link = array(
  63. '#link' => '/node/add/note',
  64. // get the content type from settings OR create the content type with module install
  65. // TODO: add data (node nid) for pre-filled reference field of new note
  66. '#attributes' => array(
  67. 'class' => array('personal-note-link', 'personal-note-create'),
  68. 'title' => t('create a note for @title.', array('@title'=>$entity->title)),
  69. 'nid' => $entity->nid,
  70. ),
  71. '#theme'=>'materio_personalnotes_note_link',
  72. );
  73. if(isset($link)){
  74. dsm($link, 'link');
  75. drupal_add_js(drupal_get_path('module', 'materio_personalnotes').'/js/dist/materio_personalnotes.min.js');
  76. return $link;
  77. }
  78. return;
  79. }
  80. /**
  81. * Implements hook_theme().
  82. */
  83. function materio_personalnotes_theme($existing, $type, $theme, $path) {
  84. return array(
  85. 'materio_personalnotes_note_link' => array(
  86. 'variables' => array('link' => NULL, 'attributes' => array()),
  87. ),
  88. );
  89. }
  90. function theme_materio_personalnotes_note_link($vars){
  91. return l(
  92. '<i class="fi-pencil"></i>',
  93. $vars['link'],
  94. array(
  95. 'attributes' => $vars['attributes'],
  96. 'html' => true,
  97. )
  98. );
  99. }