Hi guys
I'm discovering the Ctools modal framework, and thanks to Roger López and his post at http://zroger.com/node/31, I'm understanding the basics, and it rocks !
Now I want to do something else. I created a view that lists nodes of a specific type, and in each row I added the field 'Edit link', so this link points to node/[nid]/edit. My goal is to make this node edit form appear in a modal using Ctools. With this, the user will be able to edit the node directly in the modal, and ideally after clicking the Submit button he'll be redirected to same view but refreshed so the changes appear immediately. After many trials - like creating a custom link in the view pointing to test/%ctools_js/go and altering this menu entry in a custom module - I can't find even make the form appear in a modal.
Maybe I'm on the wrong track, so any hint and how-to would be greatly appreciated. Thanks in advance.
Comments
Comment #1
DjebbZ commentedI'm on something, and I would love some feedback, because I'm stuck here...
First, let me sum up how Modal framework works to make sure I'm not doing nonsense.
To create a modal, you register a menu to this modal with a callback function with the ctools operation. You also need to somehow create a page that holds this link in the form of "test/%ctools_js/go". Right ?
I changed a bit what I said before. I created a custom field in the view UI that is the text "Upload a new version" output as a link to the path
upload/%ctools_js/gowith the proper classctools-use-modal, so I have my link to the modal here. I registered this path inhook_menu. But the page does not appear in a modal, but in a normal page.Here's my code for you to review, with comments on the problems I encountered :
Comment #2
DjebbZ commentedOk I found something and the modal appears now !
It seems that the call to the ctoos modal framework, aka
ctools_include('modal'); ctools_modal_add_js();, doesn't work where call in the view preprocess. So I added the code in the view's header, and now the modal stuff works ! Ahaaa :) Well... it's a bit dirty, since this code is not in my .module file. Any idea on how to include this code for this page ? I can't see how to use the hook_menu_alter...Now the serious stuff. The form I want to display is a node edit form, so it needs the node object in the $form_state array. The problem is : when I'm in the function
mymodule_modal_callback, how can I retrieve the node since this information (at least the node id) is in the view ? I have no way to predict which node it is...Comment #3
tbenice commentedIm new to this and want to do something similar...did you ever figure it out? Maybe can you put the ctools calls in a template file instead of the views header?
Comment #4
DjebbZ commentedSorry, I didn't find anything at this time and gave up with the modal.
Comment #5
AndrzejG commented+ I am also VERY interested.
Comment #6
maedi commented+me
Comment #7
DjebbZ commentedClosing my own issue, since I never found any solution, and had no support.
Comment #8
couturier commentedDjebbZ, we are currently working on a very similar solution to this problem at this thread: http://drupal.org/node/828794
I'm content with putting either the whole node or just the comment form into a modal, so these are similar issues. If you would be interested in taking a look at the comments at the other issue, especially Comment #20, that would be great. It sounds like you have more experience with modals than I do, and I feel like we are so close to getting this to work. Thanks!
Comment #9
begun commented@DjebbZ I have just finished implementing the exact thing you have been trying to do. I had actually planned to write this up as a mini How-to, but haven't got the time right now. In the mean time, here is some code to put you in the right direction. Check out the $op = 'edit' part of namecards_modalframe_node(). I will assume that you already have the edit node links in your views set up correctly.
Also don't forget to load the necessary libraries and settings in the parent page for the modal. Note that I had to include 'ajax-responder' in order for all the node edit form features to work (e.g. drag-drop fields, etc.). Don't get scared by the size of this. You don't need the stuff referring to $modal_styles for it to work (I am just using it here to apply some customizations to the visual appearance of the modal).
Hope this helps
Comment #10
julien66 commentedMm... Trying to achieve the same thing since several hours already 8|
I have trouble with validation and I just can't seem to find what i am doing wrong.
Here is my code :
When I save the modal form, this results in : " The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved " !
Pretty hard.
EDIT : It's now working after adding :
just after $output = ctools_modal_form_wrapper($node->type . '_node_form', $form_state);
Comment #11
mustanggb commented