Initially added this function with the intention of getting caching onto the core hook, however that train looks to have left, and instead it is suggested that modules directly add their own caching for this hook as necessary. #1032700: Add caching to hook_admin_paths()

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

EclipseGc’s picture

Status: Active » Needs review
merlinofchaos’s picture

I actually had to revert the hook_admin_paths stuff from earlier, because it was a performance nightmare. I'm not sure where everything on that issue stands right now.

EclipseGc’s picture

OK, hopefully this will take care of the performance issue and get us the admin paths back. :-D

EclipseGc’s picture

Better patch. This time admin_path status is being checked and set for menu_rebuilding to clear the admin_paths cached items.

EclipseGc’s picture

Adding a check to only perform this stuff on custom pages since there's no reason to track it for pages with their own tasks and it only throws errors on that anyway.

EclipseGc’s picture

A better fix for 5

EclipseGc’s picture

ok, last attempt failed, trying again

jhedstrom’s picture

Re-rolling for clean apply.

merlinofchaos’s picture

Status: Needs review » Needs work
   if (!empty($form_state['clicked_button']['#save'])) {
+    if ($form_state['page']->task_id == 'page') {
+      // Check to see if the admin_paths setting has changed.
+      $form_state['page']->admin_paths_status = (!page_manager_get_page_cache($form_state['page']->task_name)->subtask['subtask']->conf['admin_paths'] == $form_state['page']->subtask['subtask']->conf['admin_paths']);
+    }

We need to not hardcode to a specific task id. We can perhaps do a callback that the page task implements, that way other tasks can share the glory if needed.

+      if ((isset($page->conf['admin_paths']) && $page->conf['admin_paths']) && (!isset($page->make_frontpage) || !$page->make_frontpage)) {

!empty() seems equivalent to the first two there. And empty() seems equivalent to the second two.

EclipseGc’s picture

Hmmm, I hard coded to the page task_id because all other tasks are generally going to be using hook_admin_paths() of some module's existing definition. i.e. we're overriding other tasks in those cases and in this one we're creating new. If there's some use case I missed here though please let me know.

And yeah, I've only become comfortable with empty() in far too recent history. hehe :-)

merlinofchaos’s picture

Use case or no, hardcoding like that is wrong.

Xomby’s picture

@merlin, this IS working (#8), and although I understand your issue with the hardcoding (generally bad, just by rule of thumb!), if left as is, what are the ramifications?

zhangtaihao’s picture

I think page_manager_edit_page_finish() is perhaps not the right place to check for this status. Granted, it works because the UI is the most common place to work out this issue. However, some piece of code could still try to save a page through page_manager_save_page_cache().

Given that all the code in page_manager_save_page_cache() seems intended to react to page & handler changes, it would be a much more logical place to rebuild admin paths cache.

I apologize for being stupid. I will avoid skipping bits and pieces in the future.

zhangtaihao’s picture

Status: Needs work » Needs review
FileSize
5.05 KB

Actually page_manager_page_form_basic_submit() seems the perfect place for the check. Incidentally, this is also where $cache->path_changed = TRUE; happens.

I've taken a slightly different approach to clear the admin paths cache. Since admin paths seem limited to the page task, I decided that the best place to detect changes is in the page handler itself (i.e. in page_manager_page_form_basic_submit()). The admin paths cache are specifically cleared in page_manager_page_save_subtask() and page_manager_page_delete() (in page.inc). Also, since whether a page is an admin page is also dependent on whether it is made the home page, the check also includes change in that option.

As such, the only changes to page_manager.module are a cached admin paths rebuild/retrieval function and a clear function.

zhangtaihao’s picture

darvanen’s picture

Issue summary: View changes

#14 Works for me.

DamienMcKenna’s picture

Assigned: EclipseGc » Unassigned

dsnopek’s picture

Status: Needs review » Needs work

I just did some manual testing, and the patch in #14 works great! I created a page in Page Manager and checked the checkbox to use the admin overlay. Enabling and disabling this checkbox would invalidate the cache correctly!

However, I did find a case where it didn't invalidate the cache when it should: if the checkbox is already checked and the page saved, then you change the pages path, and save, it won't be in the admin overlay/theme on the new path. You have uncheck the checkbox, save, then check it again and save.

Also, it's not part of this patch, but the current checkbox label is: "Use this page in an admin overlay." However, this also affects if the admin theme is used, and if you don't have overlay enabled, that's all it affects. It would be awesome if this mentioned that it affected the admin theme and didn't say anything about the overlay if the overlay module was disabled. But that's probably out of scope for this issue...

Status: Needs work » Needs review
joelpittet’s picture

Status: Needs review » Needs work

as per #19 this still needs work

darrenwh’s picture