I'm looking to write the following module, any help, guidance, and advice would be greatly appreciated.
- User is logged into site.
- Site has two content types: page & note.
- Logged in user can create content type note only.
- User is viewing a node: /node/5.
- User selects some text in the body.
- Link/icon is shown above selected text.
- User clicks clicks and is taken to /node/add/note
- Some fields are pre-populated on Node edit page, including:
- title, field_source_quote, field_entity_reference_nid
- User adds his "note" to field_user_note and saves note
From my basic understanding of JSON, I should be able to create a JSON of the user selected text with something like:
var selectedText = "";
selectedText = window.getSelection().toString();
var noteData={
"sourcePath": "/node/being/viewed",
"selectedText": selectedText
};
How do I get noteData to a module? Better yet, how do I get nodeData to the node/add/note page and pre-populate the correct fields?
Any help would be greatly appreciated.
======= Updates Below =============
Passing data through local storage (Andrew's Approach)
I can confirm this approach is viable. There are a number of issues, however that this presents:
- I'm sure this is not the most "drupal-ized" way to perform this.
- If the node admin pages use a different theme, the js to retrieve and apply the data must be within the other them.
- Need to have a persistent marker placed for the user ui (i.e. highlighting the text they have added a "note" to).
I've come across a library that might be helpful for #3: Rangy (https://github.com/timdown/rangy).