So, I'm pretty new to coding with Drupal, and learning PHP at the same time. I'm developing a custom module, and thought I'd share my experiences with this wonderful project to help improve it further. Perhaps this should be several different issues, but I'm going to lump all together at we can spin stuff out later if we want.
1) Cross-links. When you implement hook_menu, link me to the menu examples, in case I forget how the menu array needs to be structured. Form Examples also needs a plug. I doubt my use-case is that unusual - coming into D7 fresh, I'm inclined to need reminding the first few times. Make it easy for me to find what I need to be reminded of instead of hunting all over for it.
2) Inline comments. The other examples have much more extensive "//'wrapper' is the ID of the element we want to target with the callback" sort of things. These are absolutely invaluable - I /can/ parse the lines on my own, but I'll remember them better if it's explained as well.
3) Overview. It would be wonderful, if somewhere immediately visible, there were an overview of how the ajax framework works. Just a simple exposition - "We build a form (see Form API) and return it, marking certain elements as ajax capable. When these elements are modified, a callback function tells drupal what portions of the form are replaced..." etc.
4) In ajax_example_misc.inc, change drupal_add_js to drupal_add_library, and make the documentation on this point much more explicit. I glossed over "This will not work if ajax.js is not loaded on the page" several times and ended up on IRC looking for help.
5) Document all options for #ajax. I literally cannot find information anywhere on the net as to what options I can put in this array. Are there any beside 'wrapper', 'callback', 'effect' and 'method'? What are my options for effect and method? If the information is out there, then even just a link would be sufficient, but I couldn't find it.
Basically, I'd like more hand holding. Menu Examples was superb - a /huge/ portion of the file was documentation, both doxygen and inline. AJAX Examples has potential - let's make is superb as well. I'll try to put together a starter patch for discussion sometime in the next week, if no one has beaten me to the punch.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | examples.ajax_example_comment_cleanup_988850_11.patch | 33.27 KB | rfay |
| #12 | ajax_example_diff_10_11.txt | 8.73 KB | rfay |
| #10 | ajax_documentation_3.patch | 32.05 KB | threewestwinds |
| #8 | ajax_documentation.patch | 15.05 KB | threewestwinds |
| #3 | ajax_documentation.patch | 16.43 KB | threewestwinds |
Comments
Comment #1
rfayLooking forward to your patch! This is a community project, and your participation is very welcome.
Thanks,
-Randy
Comment #2
rfay@threewestwinds, in case it's useful as you get your patch together, the ajax_example module grew out of the material at http://randyfay.com/ajax (and before that http://randyfay.com/ahah).
The related handbook page (which I believe is referenced in the code) is http://drupal.org/node/752056.
Thanks for your effort on this!
-Randy
Comment #3
threewestwinds commentedI've started some work on it, but there's a lot of stuff to do. I'll take a look at your site before I do anymore, but for now here's what I've been working on. I'm up to about line ~230 in ajax_example.module, going straight through from the top (since that's the way I read it the first time, and without evidence otherwise, I think it's a natural way).
One more major change I'm considering is the removal of the dynamic_sections portion entirely. It didn't really add anything new, just reshashing previous examples in an obvious way. Perhaps other people's experience is different - I'd like to hear from some other people on this.
Comment #4
rfayRemember that this documentation is used to create the api.drupal.org examples, so has to generate good api.d.o docs.
Since you're kind enough to take this on, please take a look at http://drupal.org/coding-standards and http://drupal.org/node/1354 if you haven't already.
Why is the /7 tacked on?
I probably don't want to remove these. They're one of the best and easiest graceful degradation examples.
Use periods at the end of sentences in comments.
Thanks so much for your effort on this!
Powered by Dreditor.
Comment #5
threewestwinds commentedTake a look at http://api.drupal.org/api/examples/ajax_example--ajax_example.module/gro... - the link doesn't work as it is now. I assumed it was because D6 (the current default) has no ajax page, though I don't really know. I wish the link had worked - that page is important and would have made my life a lot easier if I'd found it sooner.
If not the dynamic_sections, then how about the one before it (dependent_dropdown_degrades)? We have two examples that show basically the same thing. That takes up reading time and attention span, which I why I want to drop one of them.
I'll have to fix a lot of the existing comments to use periods then too. I did read those two docs you linked to a while ago, but I'll look them over again. I was mostly trying to follow the style conventions that were already present.
Comment #6
rfayThe dependent dropdown is a fundamental thing that people copy and paste all the time. Sorry :-)
A lot of people use these examples not to learn, but just as starter code, so the wizard-like code and the dependent dropdown can be quite useful.
Since the AJAX example is D7, it automatically should link to D7. If not, it's probably a new API module bug.
I do see that http://api.drupal.org/api/examples/ajax_example--ajax_example.module/gro... is not rendering correctly, and hope we can get that fixed in this round, but adding ajax/7 isn't the right way to do it, since it's the group name we're referring to.
http://api.drupal.org/api/drupal/includes--ajax.inc/group/ajax/7 is the destination we wanted, which is group defined in ajax.inc. http://api.drupal.org/api/drupal/includes--ajax.inc/7/source
I filed #990108: Links and search do not make sense and are not working across projects about the issue you discovered. Nice work :-)
Comment #7
rfayAJAX Example predates Form Example. If it didn't, though, it would be part of form example. Do you think long-term we should be figuring out how to put it in there?
Comment #8
threewestwinds commentedI'm actually not so sure about that. It made a lot of sense, to me at least, to first learn how to build forms, submit, save, etc. and after that, as a separate experience, learn how to make them dynamic. Form API is functionality, AJAX Framework is presentation.
I'm not strongly attached to the idea of taking an example out, I just wanted to throw it out there. This patch includes no removal, and goes all the way to the end of the .module file. Still need to take a look at graceful_degredation.inc, misc,inc and advanced.inc.
Plus, I'd like to add some CSS for ajax-changed, so that on the advanced page it's visible. Bolding the text is simple and obvious, and then we wouldn't have to add the asterisk there (which is unrelated to the command that block is supposed to be demonstrating).
Comment #9
rfayThanks for the great work. When you post a patch, setting it to "Needs review" makes it obvious that it needs review, and also runs the automated tests.
Thanks,
-Randy
Comment #10
threewestwinds commentedI actually knew that, and was waiting until I was done working through the whole module before I set it that way. Which I have now done.
The advanced examples section really needs a complete overhaul, but I'm not up for that right now, so I left it alone. It's a different issue than just fixing the docs up anyway.
There are whitespace inconsistencies - some functions have empty lines to separate connected operations, while others do not. I attempted to enforce some consistency within each function, but it would be better if the whole module were the same.
I actually prefer it without empty lines. It may just be my Python background showing though, but every time I see an empty line, I think end of function, and it breaks my thought-flow.
Comment #11
rfayCommitted with some small changes. http://drupal.org/cvs?commit=463840 (changes are attached in the .txt file)
Thanks so much for the thoughtful work here, @threewestwinds. You are welcome anywhere in Examples. (Hoping you'll have many other learning experiences to take on :-)
(won't let me attach my patch or diff here, so I'll try in the next comment)
Comment #12
rfayHere are the files. I was able to attach successfully when turning off javascript.
Comment #13
rfayWell, it got one of the files. Here's the patch I committed.
Comment #14
rfayComment #15
threewestwinds commentedAn embarrassing number of typos in there - glad you caught them for me. "To" instead of "two"? I may die of mortification.
Comment #16
rfayWhen you do that much work, you can't see what you did any more. You *have* to have somebody else look at it :-)
The most important fixes to functional things were that drupal_add_library() call and some doxy links that were incorrect (we'll *see* if I got them right :-)
Thanks for the work on this!