I've created a custom block and put this code into php input:
if (arg(0) == 'node' && is_numeric(arg(1))) {
//load $node object
$node = node_load(arg(1));
//check for node update access
if (node_access("update", $node)){
$nid = $node->nid;
print l(t('edit'), "node/$nid/edit") .' '. l(t('delete'), "node/$nid/delete");
}
}
This code works without ajaxify. When ajaxified, it outputs nothing. The block shows up, but is empty. What's wrong?
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | ajaxify_regions.patch | 1.94 KB | Toxid |
| #12 | ajaxify_regions.patch | 1.66 KB | Toxid |
Comments
Comment #1
Toxid commentedI tried print_r ($node); and it seems that it's empty. Is there another way to load $node?
Comment #2
mikeytown2 commentedSomething like this would require a custom handler OR for the Ajaxify logic to be a lot smarter... which could happen.
http://api.drupal.org/api/function/arg/6
Store the q variable in the jquery drupal settings array and then on hook_init set $_GET['q'] back to the stored value on Ajaxify callback. In boost stats I do store the q variable, so 90% of the logic has already been figured out.
Comment #3
Toxid commentedAh, so it was the arguments that was the problem. I'm not a coder, so I'm not quite sure how to do what you describe, but thanks for pointing me in the right direction. I'll have a look at boost stats to see how it's done.
Comment #4
Toxid commentedI couldn't figure this one out. I took some code from the boost module and pasted into ajaxify regions, but I can't get the values to Drupal.settings. I removed the code I thought was unessessary, such as the if statements.
So drupal_add_js($page, 'setting'); should insert the values in the Drupal.settings array, but I can't see them when I look in the source code.
EDIT: I noticed my mistake now. I removed the sitewide code, and renamed the function so to ajaxify_regions_init. Now I get the $nid printed to Drupal.settings.
Comment #5
mikeytown2 commentedYou should be able to get it working with the following as a guide
What we want is q; but we'll call it qq since q is used by drupal via .htaccess rules.
This makes $_GET['q'] available to jQuery. Next step is to pass this back to ajaxif's callback ajaxify_regions_ajax_handler() and have that function process it.
Finally we need to process the qq variable and set that to q
Comment #6
Toxid commentedOh, this is a pretty easy code, thanks. So we're overwriting ajaxifys' js to make it add the q value. When looking in firebugs console, I can see that qq is "node/42". But the code isn't working yet, drupal gives me an error that "var blocks = "blocks='. implode('/', $ajax_blocks) .'";" is an invalid argument. I've experimented with it but cannot get it right. The block still shows nothing.
Comment #7
mikeytown2 commentedajaxify_regions_preprocess() is where the
var blocks = "blocks='. implode('/', $ajax_blocks) .'";livesComment #8
Toxid commentedIt appears I was wrong, drupal really only gave me a row number so I pasted the code at that row. But then I changed this part: var qq = "qq=Drupal.settings.ajaxify.qq"; and removed the qq=, then the code works and the console shows that the script loads correctly. This is what it looks like in the console:
GET http://localhost/xnalarapressflow/?blocks=block-18/nice_menus-1&Drupal.s...
block-18 and nice_menues-1 are the blocks I've ajaxified. For some reason, the q value isn't converted.
Comment #9
mikeytown2 commentedvar qq = "qq=" + Drupal.settings.ajaxify.qq;Comment #10
Toxid commentedI suppose I replace the drupal_add_js in the preprocess function with the new js. That works, I get "&qq=node/42" now. However, it seems to have been caught in some kind of loop, because the content is never loaded. The ajax loading image just keeps spinning. In the firebug console, the script finishes okay.
Comment #11
mikeytown2 commentedCreate a patch of what you got so far and I'll try to get some time to make it fly
Comment #12
Toxid commentedThanks, that would be great :) I'm attaching the patch. I haven't done much really, just replace the drupal_add_js in ajaxify_region_preprocess function and then added an ajaxify_regions_init function at the end to generate the variables.
Comment #13
mikeytown2 commentedFirst issue: place the
$_GET['q'] = $_GET['qq'];in ajaxify_regions_ajax_handler. you don't need to use hook_init. do it after $_GET['q'] gets used in that function.Comment #14
Toxid commentedYou did it! It works. Thank you very much! This module just got a whole lot better. I moved the code to reset arg into the handler function too. I'm attaching the final patch here.
Comment #15
Toxid commentedComment #16
mikeytown2 commentedmarking this "needs review" since it would be nice to have this functionality in this module
Comment #17
mikeytown2 commentedComment #18
csevb10 commentedOk, so the very original versions actually did exactly this, but the logic got lost somewhere along the way.
I committed what I think is a simpler/cleaner version here: http://drupal.org/cvs?commit=396738
Take a look at the diff and what I did to accomplish it, then let me know if there is anything that you feel could be done better:
http://drupalcode.org/viewvc/drupal/contributions/modules/ajaxify_region...
Comment #19
mikeytown2 commentedI've found $_SERVER['HTTP_REFERER'] to not be 100% reliable (what referer_uri() uses).
You might also want to consider using javascript to get the current URL http://stackoverflow.com/questions/406192/how-to-get-the-current-url-in-... If going this route or using the code you currently have I would opt to set 'q' and then run drupal_init_path() again.
Comment #21
asak commented@mikeytown2: This issue is closed, but it doesn't seem like your last suggestion was considered.
If I understand you correctly, you're saying that line 61 in the _ajax_handler function -
$_GET['q'] = $ref_uri;- should be followed by a simple call todrupal_init_path();? is that it?I seem to be bumping into you more often lately on d.o - I like it. you're doing awesome work ;)
Comment #22
mikeytown2 commentedTo answer your question, yes do this
Good example is the front page. $_GET['q'] will be empty, but after running drupal_init_path(), $_GET['q'] will then be set correctly.
Also
I highly recommending passing
document.referrerback in the data object of your ajax call... or at least having that as an option. Reason I say option has to do with caching of the ajax. If the block returns differently depending on where it thinks it is, and the ajax is cached, then the wrong info could show up. Granted this isn't an issue right now because the usage for this project is fairly small and blocks that use arg() is not a common thing and caching the output of this is not that common for people who use this module. Also if none of my blocks use arg(), and I do cache, then I would want returningdocument.referrerin GET parameter off so my cache hit rate will be higher for that set of blocks.Long story short, I hope this project goes to a per block configuration style; it would offer more configuration options... although I do like the ability to do
*and get all block variants.