added link with query for target node id and prepopulated node form

This commit is contained in:
Bachir Soussi Chiadmi
2017-11-27 15:21:32 +01:00
parent bbeb5f01ac
commit 268c8b619b
7 changed files with 153 additions and 53 deletions

View File

@@ -74,7 +74,11 @@ function materio_personalnotes_get_note_link($entity){
// else create one
#create new list
$link = array(
'#link' => '/node/add/note',
'#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(
@@ -86,7 +90,7 @@ function materio_personalnotes_get_note_link($entity){
);
if(isset($link)){
dsm($link, 'link');
// dsm($link, 'link');
drupal_add_js(drupal_get_path('module', 'materio_personalnotes').'/js/dist/materio_personalnotes.min.js');
return $link;
}
@@ -94,26 +98,93 @@ function materio_personalnotes_get_note_link($entity){
return;
}
/**
* Implements hook_form_alter().
*/
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');
// $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().
*/
function materio_personalnotes_theme($existing, $type, $theme, $path) {
return array(
'materio_personalnotes_note_link' => array(
'variables' => array('link' => NULL, 'attributes' => array()),
'variables' => array('path' => NULL, 'query' => array(), 'attributes' => array()),
),
);
}
function theme_materio_personalnotes_note_link($vars){
return l(
'<i class="fi-pencil"></i>',
$vars['link'],
'<i class="fi-pencil"></i>',
$vars['path'],
array(
'attributes' => $vars['attributes'],
'html' => true,
'query' => $vars['query'],
)
);
}