diff --git a/panels_page/panels_page.read.inc b/panels_page/panels_page.read.inc index 447cd047a7022d80610781029a5d20fac5de8787..1991f92630256edc9bcafef000ae1cc4e94cafcc 100644 --- a/panels_page/panels_page.read.inc +++ b/panels_page/panels_page.read.inc @@ -203,39 +203,54 @@ function panels_page_fetch_primary_display(&$panel_page) { } function panels_page_fetch_alternate_display(&$panel_page, $id) { + // Get the metadata abpit the requested display. $info = $panel_page->displays[$id]; + // Using the metadata, determine if the desired display exists. $requested_display_exists = panels_page_fetch_display_from_info($panel_page, $info, $id); - if (!$requested_display_exists) { - // The requested display does not exist. First, we try to fall back to the - // default display for the context we're switching on. - if (!empty($info['default']) && !empty($panel_page->displays[$info['default']])) { - panels_page_fetch_display_from_info($panel_page, $panel_page->displays[$info['default']], $id); - } - // Otherwise, use the primary display. Load it if it's not already loaded. - else { + if ($requested_display_exists) { + // The requested display exists. Drop the $id into $current and bug out. + $panel_page->current = $id; + return; + } + + // The requested display does not exist - determine the fallback display. We + // save the $id into the object because we'll need it later for updating + // the metadata if we export & save the default we fetch here. + $panel_page->export = $id; + // First, check for a default display for the context we're switching on, + // and try to load that. + if (!empty($info['default']) && !empty($panel_page->displays[$info['default']])) { + // A default has been defined - figure out if it actually has a display + // associated with it. + if (!panels_page_fetch_display_from_info($panel_page, $panel_page->displays[$info['default']], $id)) { + // No display is associated with the switched default either, so double + // fall back to the primary display. Load it if it's not already. panels_page_fetch_primary_display($panel_page); } } - return TRUE; + // There's no default display defined for the context we're switching on, so + // just use the primary display as the default. Load it if it's not already. + else { + panels_page_fetch_primary_display($panel_page); + } } /** * Get a display based on whether it's already in code or needs to be loaded. */ function panels_page_fetch_display_from_info(&$panel_page, $info, $id) { - $ret = NULL; // If the 'display' is set it's the result of an export/default if (isset($info['display'])) { $panel_page->display = $info['display']; - $panel_page->current = $id; return TRUE; } + // If the $did is numeric, it corresponds to an existing display - load it. if (is_numeric($info['did'])) { $panel_page->display = panels_load_display($info['did']); - $panel_page->current = $id; return TRUE; } + return FALSE; }