hi guys,

when i create a page display with delete link in field and full page 10 per page.

After the unique record on page 2 (for example) is removed (as described in the initial post), user is redirected to an empty page 2, with no pager and empty message displayed....
Most likely, because I would guess the query is run by Views for page 2, so there would be something like LIMIT 10, OFFSET 10 in the query which returns an empty results set (since a record has just been removed).

Comments

ycshen’s picture

StatusFileSize
new1.16 KB

hi,

I create a patch for this problem.
if my patch is wrong,please let's me know.

if there are some other solutions,please share with me.

jerenus’s picture

Version: 7.x-3.7 » 7.x-3.x-dev
Status: Active » Needs review

Bot.

jerenus’s picture

ycshen’s picture

StatusFileSize
new9.96 KB
new4.84 KB
new9.09 KB

Thank @DYdave 's help in DGO.
we talk about this problem on the following link.
https://groups.drupal.org/node/299073#comment-928483

the attachment is the example:

  1. i have 11 items.
  2. create a view has delete link,full pager 10 item per page,so page 2 have unique item.
  3. when i delete the unique one,the destantion will rediret to page 2 ,and page 2 is empty.

my patch will fix this problem, if a unique item in a page,when delete it ,the destantion will rediret to the previous page.

dawehner’s picture

Thank you for the patch!

+++ b/modules/node/views_handler_field_node_link_delete.incundefined
@@ -25,6 +25,15 @@ class views_handler_field_node_link_delete extends views_handler_field_node_link
+    if(count($this->view->result) == 1 && $this->view->query->offset >= $this->view->query->limit){
+      $destination = drupal_get_destination();
+      $url_query = parse_url($destination['destination']);
+      parse_str($url_query['query'], $url_data);
+      $url_data['page'] = $url_data['page'] - 1;
+      $destination['destination'] =  $url_query['path'] . '?' . http_build_query($url_data);
+      $this->options['alter']['query'] = $destination;
+    }

This is probably the case in many other situations (like comment delete etc.) so what about make this more generic and move this to a function? Additional: this really needs some documentation what is the problem and how we fix it. (I understand that, but many others won't)

alfababy’s picture

StatusFileSize
new1.79 KB

hi,

@ycshen, your patch is very useful.
I follow your patch add a option that user can choose whether enable this function. Maybe we can let user to choose it. That's friendly.

Cheers.

ycshen’s picture

Issue tags: +delete link, +destination, +#views
StatusFileSize
new4.09 KB

Hi guys,

Really sorry for the late follow-up on this issue but it has taken us more time than expected to investigate and get back to this ticket with an updated patch.

As @dawehner mentioned at #5:

This is probably the case in many other situations (like comment delete etc.) so what about make this more generic and move this to a function?

Indeed, after further investigation we found out it would be the case in several other situations and certainly agree that making a generic function would be the way to go.
If there isn't a generic method, the code would have to be duplicated in several places which would be redundant.

Which handlers would have to be modified? (in which situations would this issue occur?)

So we would need to add a new method that would be common to these field handlers.

By getting back in the tree of views handlers, we found out this problem would occur for node, node revisions, user and comments, which would seem to inherit from the views_handler_field or views_handler_field_entity classes.

However, the User cancel link only extends the views_handler_field class, not to mention third party modules, so it seems that if we were to add a new method, we wouldn't have much choice other than adding it to the views_handler_field class.

Please find attached to this comment an updated patch against views-7.x-3.x at 22bf853, which adds a new method called delete_get_destination in views_handler_field.inc.
File attached as: views-delete-link-destination-2004960-7.patch.

The new method delete_get_destination allows overriding the standard drupal_get_destination() to redirect the user to the previous (page-1) if no results are found on the previous page, except for page 1.
Additionally, the patch will modify accordingly the node, revisions, comments and user delete related link field handlers to use the newly added method.

You will notice this patch doesn't have much documentation yet, because I wanted to first run the code through your validation to double check if this approach would seem more reasonable to you (than previous patch from #1).

If everything is fine with the code, I would surely be glad to work on adding more inline comments and improving Doc comment blocks since this is a significant new change.

Feel free to let me know if you would have any more comments, objections, feedbacks, issues or ideas with this updated patch, I would surely be glad to provide more information or explain in further details.

Thanks in advance to everyone for your comments, reviews, feedbacks and testing.
Cheers!

el1_1el’s picture

I tried the above patch (7) and it didn't really help my use case (perhaps I'm not using it correctly?). I'm trying to redirect users back to their main organic group page when they delete og content. So I ended up modifying views_handler_field_node_link_delete.inc

if(isset($node->og_group_ref['und'][0]['target_id'])){ 
    $this->options['alter']['query']['destination'] = 'node/'.$node->og_group_ref['und'][0]['target_id'];
}else{
//ORIGINAL
    $this->options['alter']['query'] = drupal_get_destination();
//END ORIGINAL
}

I'm wondering if maybe the destination parameter could(should?) be set in the Views UI using tokens?...or if perhaps my use case is too marginal for such a major overhaul.

ycshen’s picture

hi el ,

I think you should use delete_get_destination() in stated of drupal_get_destination() in your handler

el1_1el’s picture

Issue tags: -delete link, -destination

Thanks for the quick reply ycshen.

I forgot to mention something that may make my use case even more marginal (and a bit different from yours) so i'll explain in a bit more detail in case its relevant for you or anyone else.

When I tried the patch using delete_get_destination (without my og modification above), I was redirected to my default 404 page after deleting a node...which is what also happens when I use the original views code with drupal_get_destination. This is almost certainly because I am using a content pane view to generate custom buttons (including delete) for users, and embedding that button view in a node_view panel.

You can correct me if I'm wrong here but I *think* in both cases (drupal and delete) the destination parameter tries to return to the node page (rather than a view page as in your case which would be more the norm) that has since been deleted. I tried modifying delete_get_destination when I applied the patch with a "page-2" but got the same result so I went with my og customization + the original code to try and keep it simpler. I suggested the use of a customized destination parameter in case others have a similar use case because in my case I could then just get the og_group_ref in a hidden field of the view, and put it in as a token in a customized destination parameter....which is essentially what i'm doing in my customized handler.

Let me know if any of that doesnt make sense and i'll try to explain it a little better...but given that info do you think delete_get_destination would be useful in my case? I'm happy to test this further or perhaps help a bit with the code if I can. Thanks again

ycshen’s picture

hi el,

I think you need to find other issues and my patch can't help you fix your problem if drupal_get_destination also doesn't work.
And I will still try to help you to debug.
please make sure the following code worked well.

if(isset($node->og_group_ref['und'][0]['target_id'])){ 
    $this->options['alter']['query']['destination'] = 'node/'.$node->og_group_ref['und'][0]['target_id'];
}

please provide some information:

  1. url before delete the content
  2. url after delete the content
  3. url after delete the content you expected
  4. Attach the customized handler inc you defined
el1_1el’s picture

Hi ycshen,

So basically the url before delete is /node/123. I hit delete to delete /node/123. Then either drupal_get_destination or delete_get_destination tries to return me to /node/123...which I just deleted. So I added

if(isset($node->og_group_ref['und'][0]['target_id'])){ 
    $this->options['alter']['query']['destination'] = 'node/'.$node->og_group_ref['und'][0]['target_id'];
}

to the original views_handler_field_node_link_delete.inc to return the user to the main og group page (node/12 for example) after they delete /node/123. This works just fine and I dont need to change it...I am just suggesting that adding a feature to the patch that allows one to set a custom destination in the views UI might be useful to others as well.

Thanks for the offer to assist and your work on the patch!

cheers,
el

ycshen’s picture

hi el,

Have you tried to define your own custom handler 'file[]=xxxx.inc' in info and inextend the views_handler_field_node_link_delete.inc handler with your own custom handler , which you could override the method:
delete_get_destination()
and add your code in there.....

Then in the View you should change the delete field handler you are currently using and use instead the custom handler you have created.

This would avoid having to modify the handler views_handler_field_node_link_delete.inc.
Please let us know if you are able to get any results with this method, it would be interesting for the work carried in this ticket.

gribnif’s picture

There is another bug report, #1009646: Rendered links token replacement URL encoding is broken which contains a much simpler fix for this problem. The patch in #24 was written to fix a bug in token substitution, but it also fixes the destination and edit link with pager bug described here.

chris matthews’s picture

Issue summary: View changes
Status: Needs review » Closed (duplicate)
Issue tags: -#views