Comments

damienmckenna’s picture

damienmckenna’s picture

Is there another way of doing this?

michelle’s picture

I tested this and the patch still applies cleanly. If I make a function test_panels_ipe_ajax_save_commands_alter(), it gets called. So that much works.

But the function hook_panels_ipe_ajax_save_commands_alter() never runs so the code in there to redirect to the home page doesn't run. Is it supposed to? I'm not sure how that code is even related to this issue or why you want to have the redirect. If you're using IPE, wouldn't you want to stay on the same page after saving?

robmcbryde queued 1: panels-n2363275-1.patch for re-testing.

eclipsegc’s picture

Title: Allow IPE submission commands to be altered » IPE needs to allow for more nuanced save commands
StatusFileSize
new1.84 KB

Ok, I wrote REALLY similar code to this earlier today for functionally similar reasons (workbench_moderation being the bane of my existence) and had fairly limited success because the cache is still locked, which makes redirects semi-non-functional. This lead to trying to turn off the lock which looks like it can be done via ajax, but my kung fu failed me there, so I sat and thought about it for a while. Seems to me the more important thing here is that panelizer (and really any module that's going to interface with panel renderers) needs to have a bit of code that gets consulted during the save process. This is pretty entangled no matter how I cut it, so this patch is a rough "what if" scenario. Since we can't do panelizer plugins per bundle, this still doesn't quite get as far as letting workbench_moderation get what it needs out of the situation, and now I'm expecting these sorts of plugins to account for every renderer out there (easy when we only have 2 or 3, but fundamentally a design flaw in my suggestion here which I acknowledge). Still if we replaced my code here with a call to some method on the plugin, we could get similar results and not require IPE to special case each plugin type that might come along.

Let me know what a better solution is.

Eclipse

PS: In this code, workbench_moderation would need to hijack node's uri callback and nuance the return so that node/%node/draft and the various available revisions could be properly forwarded to, but at least this makes it possible.

eclipsegc’s picture

Oh, and to illustrate the problem here, panelizer and IPE (workbench_moderation or no) have an integration issue around revisions right now. If you were to "Customize this page" add a pane, save and then customize the page and add another pane (all without ever refreshing) you'll end up with a block that has no controls on it, and that block won't show up in any of your revisions because IPE is saving it to a cache we don't ever use again (I think...) My solution in the above patch is a brute force page refresh for the sake of absolutely proving I can kill the problem. A more elegant solution hopefully exists.

Eclipse

eclipsegc’s picture

Also, apologies I kind of hijacked this issue since I think we have the same ultimate goal, if not I'll start my own issue. :-D

damienmckenna’s picture

@eclipse: That's ok, my suggestion was purely from the POV of getting it to work better with Panelizer and WM, so if there's a better way then I'm completely ok with it.

joelstein’s picture

Here's a patch that runs with DamienMcKenna's idea, but expands on it to a single hook to alter all ajax commands issued by IPE.

For example, you could implement this in a module to redirect after saving or changing layout:

function mymodule_panels_ipe_ajax_commands_alter(&$renderer, $context) {
  if (
    in_array($context['op'], array('save_form', 'set_layout'))
    && !empty($context['form_state']['clicked_button']['#save-display'])
  ) {
    $renderer->commands[] = ctools_ajax_command_redirect($_SESSION['some_path']);
  }
}

The patch looks like I changed a lot, but that's just because I had to wrap some stuff in if/else statements so we could get to end of each ajax method where the commands are altered.

@EclipseGc: FYI, you can invoke hook_panels_cache_save() to add code which gets consulted during saving.

eyilmaz’s picture

Status: Needs review » Reviewed & tested by the community

+1 for patch in #10. Must have to make panelizer with revisions work smooth.
Works for us.

joelstein’s picture

Thanks for the review! One use case I use in lots of projects with this patch is to automatically re-initialize IPE editing after changing layout, because I've found that's what most of clients do right after changing layout.

With this patch, you can easily do something like this:

function MYMODULE_panels_ipe_ajax_commands_alter(&$renderer, $context) {
  // After changing and saving the layout, initiate edit mode again.
  if ($context['op'] === 'set_layout' && !empty($context['form_state']['clicked_button']['#save-display'])) {
    $renderer->commands[] = ajax_command_invoke('.panels-ipe-startedit', 'click');
  }
}
kopeboy’s picture

@joelstein you might want to see the specific issue I created for this
#1572202: IPE changes aren't shown after second save without page refresh

japerry’s picture

Status: Reviewed & tested by the community » Needs review

I'd like to see some more reviews before committing this. Taking out of RTBC queue for 3.9.

temoor’s picture

Re-rolled patch against latest dev version.

lwalley’s picture

lwalley’s picture

Patch upload fail, re-upload of #16 patch file and interdiff.