materio-base-legacy/sites/all/modules/gui/materiobasemod/materio_personalnotes.module

120 lines
3.0 KiB
Plaintext

<?php
/**
* Implements hook_init().
*/
function materio_personalnotes_init() {
drupal_add_js(drupal_get_path('module', 'materio_personalnotes').'/js/materio_personalnotes.js');
}
/**
* Implements hook_permission().
*/
function materio_personalnotes_permission() {
$perms = array(
'create own personal notes' => array(
'title' => t('Create own personal notes'),
'description' => t('Create own personal notes'),
),
);
return $perms;
}
// function materio_personalnotes_menu(){
// $items = array();
//
// $base = array(
// 'type' => MENU_CALLBACK,
// 'file' => 'materio_personalnotes.pages.inc',
// );
//
// $items['materio_personalnotes/registerblock'] = $base+array(
// 'title' => 'Materio base user ajax',
// 'page callback' => 'materio_personalnotes_registerblock',
// // 'page arguments' => array(),
// 'access callback' => TRUE,
// );
//
// return $items;
// }
/**
* Implements hook_menu_alter().
*/
// function materio_personalnotes_menu_alter(&$items) {
// $items['user/%user']['access callback'] = 'user_access';
// $items['user/%user']['access arguments'] = array('view own user profile');
// }
/**
* Implements hook_entity_view().
*
* Note this is broken for taxonomy terms. @see http://drupal.org/node/1067120
*/
function materio_personalnotes_entity_view($entity, $type, $view_mode, $langcode) {
if($type == 'node'){
if(user_access('create own personal notes') && $view_mode != 'print'){
$entity->content['personalnotelink'] = materio_personalnotes_get_note_link($entity);
// drupal_add_css(drupal_get_path('module', 'flag') . '/theme/flag.css');
// drupal_add_js(drupal_get_path('module', 'flag') . '/theme/flag.js');
}
}
}
function materio_personalnotes_get_note_link($entity){
// if note alredy exists link to it
// else create one
#create new list
$link = array(
'#link' => '/node/add/note',
// get the content type from settings OR create the content type with module install
// TODO: add data (node nid) for pre-filled reference field of new note
'#attributes' => array(
'class' => array('personal-note-link', 'personal-note-create'),
'title' => t('create a note for @title.', array('@title'=>$entity->title)),
'nid' => $entity->nid,
),
'#theme'=>'materio_personalnotes_note_link',
);
if(isset($link)){
dsm($link, 'link');
drupal_add_js(drupal_get_path('module', 'materio_personalnotes').'/js/dist/materio_personalnotes.min.js');
return $link;
}
return;
}
/**
* Implements hook_theme().
*/
function materio_personalnotes_theme($existing, $type, $theme, $path) {
return array(
'materio_personalnotes_note_link' => array(
'variables' => array('link' => NULL, 'attributes' => array()),
),
);
}
function theme_materio_personalnotes_note_link($vars){
return l(
'<i class="fi-pencil"></i>',
$vars['link'],
array(
'attributes' => $vars['attributes'],
'html' => true,
)
);
}