Browse Source

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

Bachir Soussi Chiadmi 6 years ago
parent
commit
268c8b619b

+ 6 - 25
sites/all/modules/features/materio_personal_notes/materio_personal_notes.features.field_base.inc

@@ -35,44 +35,25 @@ function materio_personal_notes_field_default_field_bases() {
     'type' => 'text_long',
   );
 
-  // Exported field_base: 'field_target_content'.
-  $field_bases['field_target_content'] = array(
+  // Exported field_base: 'field_target_content_nid'.
+  $field_bases['field_target_content_nid'] = array(
     'active' => 1,
     'cardinality' => 1,
     'deleted' => 0,
     'entity_types' => array(),
-    'field_name' => 'field_target_content',
+    'field_name' => 'field_target_content_nid',
     'field_permissions' => array(
       'type' => 1,
     ),
-    'indexes' => array(
-      'target_id' => array(
-        0 => 'target_id',
-      ),
-    ),
+    'indexes' => array(),
     'locked' => 0,
-    'module' => 'entityreference',
+    'module' => 'number',
     'settings' => array(
       'entity_translation_sync' => FALSE,
-      'handler' => 'base',
-      'handler_settings' => array(
-        'behaviors' => array(
-          'views-select-list' => array(
-            'status' => 0,
-          ),
-        ),
-        'sort' => array(
-          'type' => 'none',
-        ),
-        'target_bundles' => array(
-          'materiau' => 'materiau',
-        ),
-      ),
       'profile2_private' => FALSE,
-      'target_type' => 'node',
     ),
     'translatable' => 0,
-    'type' => 'entityreference',
+    'type' => 'number_integer',
   );
 
   return $field_bases;

+ 12 - 8
sites/all/modules/features/materio_personal_notes/materio_personal_notes.features.field_instance.inc

@@ -87,8 +87,8 @@ function materio_personal_notes_field_default_field_instances() {
     ),
   );
 
-  // Exported field_instance: 'node-note-field_target_content'.
-  $field_instances['node-note-field_target_content'] = array(
+  // Exported field_instance: 'node-note-field_target_content_nid'.
+  $field_instances['node-note-field_target_content_nid'] = array(
     'bundle' => 'note',
     'default_value' => NULL,
     'deleted' => 0,
@@ -144,18 +144,22 @@ function materio_personal_notes_field_default_field_instances() {
       ),
     ),
     'entity_type' => 'node',
-    'field_name' => 'field_target_content',
-    'label' => 'Target content',
+    'field_name' => 'field_target_content_nid',
+    'label' => 'Target content nid',
     'required' => 1,
     'settings' => array(
       'entity_translation_sync' => FALSE,
+      'max' => '',
+      'min' => '',
+      'prefix' => '',
+      'suffix' => '',
       'user_register_form' => FALSE,
     ),
     'widget' => array(
-      'active' => 1,
-      'module' => 'field_extrawidgets',
+      'active' => 0,
+      'module' => 'number',
       'settings' => array(),
-      'type' => 'field_extrawidgets_hidden',
+      'type' => 'number',
       'weight' => 1,
     ),
   );
@@ -163,7 +167,7 @@ function materio_personal_notes_field_default_field_instances() {
   // Translatables
   // Included for use with string extractors like potx.
   t('Note');
-  t('Target content');
+  t('Target content nid');
 
   return $field_instances;
 }

+ 4 - 2
sites/all/modules/features/materio_personal_notes/materio_personal_notes.info

@@ -9,15 +9,16 @@ dependencies[] = materio_page_title
 dependencies[] = materio_personalnotes
 dependencies[] = metatag
 dependencies[] = node
+dependencies[] = number
 dependencies[] = override_node_options
 dependencies[] = strongarm
 dependencies[] = text
 features[ctools][] = strongarm:strongarm:1
 features[features_api][] = api:2
 features[field_base][] = field_personal_note
-features[field_base][] = field_target_content
+features[field_base][] = field_target_content_nid
 features[field_instance][] = node-note-field_personal_note
-features[field_instance][] = node-note-field_target_content
+features[field_instance][] = node-note-field_target_content_nid
 features[node][] = note
 features[user_permission][] = create note content
 features[user_permission][] = create own personal notes
@@ -53,6 +54,7 @@ features[variable][] = metatag_enable_node__note
 features[variable][] = node_options_note
 features[variable][] = node_preview_note
 features[variable][] = node_submitted_note
+features[variable][] = nodeformscols_field_placements_note_default
 features[variable][] = print_html_display_comment_note
 features[variable][] = print_html_display_note
 features[variable][] = print_html_display_urllist_note

+ 42 - 0
sites/all/modules/features/materio_personal_notes/materio_personal_notes.strongarm.inc

@@ -194,6 +194,48 @@ function materio_personal_notes_strongarm() {
   $strongarm->value = TRUE;
   $export['metatag_enable_node__note'] = $strongarm;
 
+  $strongarm = new stdClass();
+  $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */
+  $strongarm->api_version = 1;
+  $strongarm->name = 'nodeformscols_field_placements_note_default';
+  $strongarm->value = array(
+    'additional_settings' => array(
+      'region' => 'footer',
+      'weight' => '1',
+      'has_required' => FALSE,
+      'title' => 'Vertical tabs',
+      'hidden' => 1,
+    ),
+    'actions' => array(
+      'region' => 'main',
+      'weight' => '2',
+      'has_required' => FALSE,
+      'title' => 'Save',
+      'hidden' => 0,
+    ),
+    'entity_translation_entity_form_language_update' => array(
+      'region' => 'footer',
+      'weight' => '0',
+      'has_required' => FALSE,
+      'title' => NULL,
+      'hidden' => 1,
+    ),
+    'field_personal_note' => array(
+      'region' => 'main',
+      'weight' => '1',
+      'has_required' => FALSE,
+      'title' => 'Note',
+      'hidden' => 0,
+    ),
+    'field_target_content_nid' => array(
+      'region' => 'main',
+      'weight' => '0',
+      'has_required' => TRUE,
+      'title' => 'Target content nid',
+    ),
+  );
+  $export['nodeformscols_field_placements_note_default'] = $strongarm;
+
   $strongarm = new stdClass();
   $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */
   $strongarm->api_version = 1;

+ 76 - 5
sites/all/modules/gui/materiobasemod/materio_personalnotes.module

@@ -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,7 +98,73 @@ 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().
@@ -102,18 +172,19 @@ function materio_personalnotes_get_note_link($entity){
 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'],
     )
   );
 }

+ 12 - 12
sites/all/themes/gui/materiobasetheme/css/styles.css

@@ -4267,9 +4267,9 @@ article.node-materiau.vm-bookmark, article.node-breve.vm-bookmark {
       margin: 0; }
     article.node-materiau.vm-bookmark nav.nav section, article.node-breve.vm-bookmark nav.nav section {
       position: relative; }
-      article.node-materiau.vm-bookmark nav.nav section > i, article.node-breve.vm-bookmark nav.nav section > i {
+      article.node-materiau.vm-bookmark nav.nav section > i, article.node-materiau.vm-bookmark nav.nav section > a, article.node-breve.vm-bookmark nav.nav section > i, article.node-breve.vm-bookmark nav.nav section > a {
         margin: 0 5px; }
-        article.node-materiau.vm-bookmark nav.nav section > i:hover, article.node-breve.vm-bookmark nav.nav section > i:hover {
+        article.node-materiau.vm-bookmark nav.nav section > i:hover, article.node-materiau.vm-bookmark nav.nav section > a:hover, article.node-breve.vm-bookmark nav.nav section > i:hover, article.node-breve.vm-bookmark nav.nav section > a:hover {
           cursor: pointer; }
     article.node-materiau.vm-bookmark nav.nav ul, article.node-breve.vm-bookmark nav.nav ul {
       position: absolute;
@@ -4469,9 +4469,9 @@ article.node-materiau.vm-cardsmall, article.node-breve.vm-cardsmall {
       margin: 0; }
     article.node-materiau.vm-cardsmall nav.nav section, article.node-breve.vm-cardsmall nav.nav section {
       position: relative; }
-      article.node-materiau.vm-cardsmall nav.nav section > i, article.node-breve.vm-cardsmall nav.nav section > i {
+      article.node-materiau.vm-cardsmall nav.nav section > i, article.node-materiau.vm-cardsmall nav.nav section > a, article.node-breve.vm-cardsmall nav.nav section > i, article.node-breve.vm-cardsmall nav.nav section > a {
         margin: 0 5px; }
-        article.node-materiau.vm-cardsmall nav.nav section > i:hover, article.node-breve.vm-cardsmall nav.nav section > i:hover {
+        article.node-materiau.vm-cardsmall nav.nav section > i:hover, article.node-materiau.vm-cardsmall nav.nav section > a:hover, article.node-breve.vm-cardsmall nav.nav section > i:hover, article.node-breve.vm-cardsmall nav.nav section > a:hover {
           cursor: pointer; }
     article.node-materiau.vm-cardsmall nav.nav ul, article.node-breve.vm-cardsmall nav.nav ul {
       position: absolute;
@@ -4733,9 +4733,9 @@ article.node-materiau.vm-cardmedium, article.node-breve.vm-cardmedium {
       margin: 0; }
     article.node-materiau.vm-cardmedium nav.nav section, article.node-breve.vm-cardmedium nav.nav section {
       position: relative; }
-      article.node-materiau.vm-cardmedium nav.nav section > i, article.node-breve.vm-cardmedium nav.nav section > i {
+      article.node-materiau.vm-cardmedium nav.nav section > i, article.node-materiau.vm-cardmedium nav.nav section > a, article.node-breve.vm-cardmedium nav.nav section > i, article.node-breve.vm-cardmedium nav.nav section > a {
         margin: 0 5px; }
-        article.node-materiau.vm-cardmedium nav.nav section > i:hover, article.node-breve.vm-cardmedium nav.nav section > i:hover {
+        article.node-materiau.vm-cardmedium nav.nav section > i:hover, article.node-materiau.vm-cardmedium nav.nav section > a:hover, article.node-breve.vm-cardmedium nav.nav section > i:hover, article.node-breve.vm-cardmedium nav.nav section > a:hover {
           cursor: pointer; }
     article.node-materiau.vm-cardmedium nav.nav ul, article.node-breve.vm-cardmedium nav.nav ul {
       position: absolute;
@@ -5089,9 +5089,9 @@ article.node-materiau.vm-cardbig, article.node-breve.vm-cardbig {
       margin: 0; }
     article.node-materiau.vm-cardbig nav.nav section, article.node-breve.vm-cardbig nav.nav section {
       position: relative; }
-      article.node-materiau.vm-cardbig nav.nav section > i, article.node-breve.vm-cardbig nav.nav section > i {
+      article.node-materiau.vm-cardbig nav.nav section > i, article.node-materiau.vm-cardbig nav.nav section > a, article.node-breve.vm-cardbig nav.nav section > i, article.node-breve.vm-cardbig nav.nav section > a {
         margin: 0 5px; }
-        article.node-materiau.vm-cardbig nav.nav section > i:hover, article.node-breve.vm-cardbig nav.nav section > i:hover {
+        article.node-materiau.vm-cardbig nav.nav section > i:hover, article.node-materiau.vm-cardbig nav.nav section > a:hover, article.node-breve.vm-cardbig nav.nav section > i:hover, article.node-breve.vm-cardbig nav.nav section > a:hover {
           cursor: pointer; }
     article.node-materiau.vm-cardbig nav.nav ul, article.node-breve.vm-cardbig nav.nav ul {
       position: absolute;
@@ -5441,9 +5441,9 @@ article.node-materiau.vm-cardfull, article.node-breve.vm-cardfull {
       margin: 0; }
     article.node-materiau.vm-cardfull nav.nav section, article.node-breve.vm-cardfull nav.nav section {
       position: relative; }
-      article.node-materiau.vm-cardfull nav.nav section > i, article.node-breve.vm-cardfull nav.nav section > i {
+      article.node-materiau.vm-cardfull nav.nav section > i, article.node-materiau.vm-cardfull nav.nav section > a, article.node-breve.vm-cardfull nav.nav section > i, article.node-breve.vm-cardfull nav.nav section > a {
         margin: 0 5px; }
-        article.node-materiau.vm-cardfull nav.nav section > i:hover, article.node-breve.vm-cardfull nav.nav section > i:hover {
+        article.node-materiau.vm-cardfull nav.nav section > i:hover, article.node-materiau.vm-cardfull nav.nav section > a:hover, article.node-breve.vm-cardfull nav.nav section > i:hover, article.node-breve.vm-cardfull nav.nav section > a:hover {
           cursor: pointer; }
     article.node-materiau.vm-cardfull nav.nav ul, article.node-breve.vm-cardfull nav.nav ul {
       position: absolute;
@@ -5747,9 +5747,9 @@ article.node-materiau.vm-cardfull, article.node-breve.vm-cardfull {
           margin: 0; }
         .print-node-materiau nav.nav section {
           position: relative; }
-          .print-node-materiau nav.nav section > i {
+          .print-node-materiau nav.nav section > i, .print-node-materiau nav.nav section > a {
             margin: 0 5px; }
-            .print-node-materiau nav.nav section > i:hover {
+            .print-node-materiau nav.nav section > i:hover, .print-node-materiau nav.nav section > a:hover {
               cursor: pointer; }
         .print-node-materiau nav.nav ul {
           position: absolute;

+ 1 - 1
sites/all/themes/gui/materiobasetheme/scss/styles.scss

@@ -1510,7 +1510,7 @@ $cardfull_h:610px;
     section{
       position:relative;
 
-      &>i{margin: 0 5px; &:hover{cursor:pointer;}}
+      &>i, &>a{margin: 0 5px; &:hover{cursor:pointer;}}
     }
 
     ul{