personnale notes front ajax is working, remains to improve the display, do it like liked materiaux

This commit is contained in:
Bachir Soussi Chiadmi
2017-11-28 17:02:45 +01:00
parent 268c8b619b
commit 7d5bedcb0c
8 changed files with 357 additions and 158 deletions

View File

@@ -23,23 +23,32 @@ function materio_personalnotes_permission() {
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;
// }
function materio_personalnotes_menu(){
$items = array();
$base = array(
'type' => MENU_CALLBACK,
'file' => 'materio_personalnotes.pages.inc',
);
$items['materio_personalnotes/form/%/%'] = $base+array(
'access arguments' => array('create own personal notes'),
'access callback' => 'user_access',
'title' => 'Materio base create/edit note ajax',
'page callback' => 'materio_personalnotes_createeditnote',
'page arguments' => array(2,3),
);
$items['materio_personalnotes/save/%'] = $base+array(
'access arguments' => array('create own personal notes'),
'access callback' => 'user_access',
'title' => 'Materio base save note ajax',
'page callback' => 'materio_personalnotes_savenote',
'page arguments' => array(2),
);
return $items;
}
/**
* Implements hook_menu_alter().
@@ -55,9 +64,9 @@ function materio_personalnotes_permission() {
* 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'){
// dsm($entity, 'entity');
if($type == 'node' && $entity->type == "materiau"){
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');
@@ -68,28 +77,51 @@ function materio_personalnotes_entity_view($entity, $type, $view_mode, $langcode
}
function materio_personalnotes_get_note_link($entity){
global $user;
// dsm($user);
// get note already created for this entity by current user
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'note')
// ->propertyCondition('status', NODE_PUBLISHED);
->propertyCondition('uid', $user->uid)
->fieldCondition('field_target_content_nid', 'value', $entity->nid)
->addMetaData('account', user_load(1));
$result = $query->execute();
// dsm($result, 'result');
// if note alredy exists link to it
// else create one
#create new list
$link = array(
'#path' => '/node/add/note',
'#query' => array(
// 'edit[field_target_content][und][0][target_id]' => $entity->title.'('.$entity->nid.')',
'target_id'=>$entity->nid,
),
// 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($result['node'])) {
// if note alredy exists link to it
$note = array_shift($result['node']);
// dsm($note, 'note');
$link = array(
'#path' => '/node/'.$note->nid.'/edit',
'#attributes' => array(
'class' => array('personal-note-link', 'personal-note-edit'),
'title' => t('Edit your @title\'s notes.', array('@title'=>$entity->title)),
'src_nid' => $entity->nid,
'note_nid' => $note->nid,
),
);
}else{
// else create one
$link = array(
// get the content type from settings OR create the content type with module install
'#path' => '/node/add/note',
'#query' => array(
'target_id'=>$entity->nid,
),
'#attributes' => array(
'class' => array('personal-note-link', 'personal-note-create'),
'title' => t('create a note for @title.', array('@title'=>$entity->title)),
'src_nid' => $entity->nid,
),
);
}
if(isset($link)){
$link['#theme'] = 'materio_personalnotes_note_link';
// dsm($link, 'link');
drupal_add_js(drupal_get_path('module', 'materio_personalnotes').'/js/dist/materio_personalnotes.min.js');
return $link;
@@ -103,69 +135,17 @@ function materio_personalnotes_get_note_link($entity){
*/
function materio_personalnotes_form_alter(&$form, &$form_state, $form_id) {
// dsm($form_id);
/*
*if (isset($form['type']) && $form['type']['#value'] . '_node_settings' == $form_id) {
* $form['workflow']['upload_' . $form['type']['#value']] = array(
* '#type' => 'radios',
* '#title' => t('Attachments'),
* '#default_value' => variable_get('upload_' . $form['type']['#value'], 1),
* '#options' => array(t('Disabled'), t('Enabled')),
* );
*}
*/
if($form_id == "note_node_form" && $target_id = $_GET['target_id']){
dsm($_GET, 'get');
dsm($target_id, 'target_id');
dsm($form, 'form');
dsm($form_state, 'form_state');
if($form_id == "note_node_form" && isset($_GET['target_id']) && $target_id = $_GET['target_id']){
// dsm($_GET, 'get');
// dsm($target_id, 'target_id');
// dsm($form, 'form');
// dsm($form_state, 'form_state');
// $form['#after_build'][] = 'materio_personalnotes_noteform_after_build';
// $form_state['field']['field_target_content']['und']['instance']['default_value'] = $target_id;
$form['field_target_content_nid']['und'][0]['value']['#default_value'] = $target_id;
$form['field_target_content_nid']['und'][0]['value']['#type'] = 'hidden';
// $form_state['field']['field_target_content']['und']['items_count'] = 1;
}
}
/**
* Implements hook_node_presave().
*/
function materio_personalnotes_node_presave($node) {
/*
*if ($node->nid && $node->moderate) {
* // Reset votes when node is updated:
* $node->score = 0;
* $node->users = '';
* $node->votes = 0;
*}
*/
/* Your code here */
}
// function materio_personalnotes_noteform_after_build($form, &$form_state) {
// dsm($_GET, 'get');
// dsm($form, 'form');
// dsm($form_state, 'form_state');
//
// $form_state['field_target_content']['und'][0]['target_id']['#default_value'] = $target_id;
//
// // switch ($form['form_id']['#value']) {
// //
// // case 'your_form':
// //
// // $form['field_yournoderef']['nid']['nid']['#value'] = arg(3);
// // $form['field_yournoderef']['#access'] = false;
// // break;
// //
// // }
//
// return $form;
//
// }
/**
* Implements hook_theme().
*/
@@ -188,3 +168,18 @@ function theme_materio_personalnotes_note_link($vars){
)
);
}
/**
* Implements hook_block_info().
*/
// function materio_personalnotes_block_info() {
//
// TODO: add my notes block
// $blocks[''] = array(
// 'info' => t(''),
// 'cache' => DRUPAL_NO_CACHE
// );
//
// return $blocks;
// }