diff --git a/modules/authcache_page_manager/authcache_page_manager.module b/modules/authcache_page_manager/authcache_page_manager.module
index e0c6ce8..0177138 100644
--- a/modules/authcache_page_manager/authcache_page_manager.module
+++ b/modules/authcache_page_manager/authcache_page_manager.module
@@ -64,76 +64,3 @@ function authcache_page_manager_authcache_page_manager_task_context_provider() {
) + $defaults,
);
}
-
-/**
- * Implements hook_authcache_p13n_admin_groups().
- */
-function authcache_page_manager_authcache_p13n_admin_groups() {
- $groups = array();
-
- if (module_exists('authcache_panels')) {
- $groups[t('Panels (by Page Manager)')] = t('To add a content pane to the list of personalized items, visit the page manager administration, edit a page, navigate to a panel variant and click on the content tab. Then set up the Authcache caching method on the respective content pane.', array('!page_manager_url' => url('admin/structure/pages')));
- }
-
- return $groups;
-}
-
-/**
- * Implements hook_authcache_panels_base_fragments().
- */
-function authcache_page_manager_authcache_panels_base_fragments() {
- $base_fragments = array();
-
- foreach (page_manager_get_tasks_by_type('page') as $task) {
- $handlers = page_manager_load_task_handlers($task);
- _authcache_page_manager_panels_collect_displays_from_handlers($handlers, $base_fragments);
-
- foreach (array_keys(page_manager_get_task_subtasks($task)) as $subtask_id) {
- $handlers = page_manager_load_task_handlers($task, $subtask_id);
- _authcache_page_manager_panels_collect_displays_from_handlers($handlers, $base_fragments);
- }
- }
-
- return array(
- 'page_manager' => $base_fragments,
- );
-}
-
-/**
- * Utility function: produce fragment defaults from page manager handler.
- */
-function _authcache_page_manager_panels_collect_displays_from_handlers($handlers, &$base_fragments) {
- $provider_map = authcache_page_manager_task_context_provider();
-
- foreach ($handlers as $handler_id => $handler) {
- if ($handler->handler == 'panel_context') {
- $did = $handler->conf['did'];
- // Add admin entry.
- $base_fragments[$did] = array(
- 'admin group' => t('Panels (by Page Manager)'),
- 'admin entry object' => array(
- '#class' => 'AuthcachePageManagerAdminEntry',
- '#arguments' => array(
- $handler->task,
- $handler->subtask,
- $handler_id,
- '@admin clients',
- '@admin entry',
- ),
- ),
- );
- // Add context provider entry.
- if (!empty($provider_map[$handler->task])) {
- $base_fragments[$did]['panels context provider'] = array(
- '#arguments' => array(
- $handler->task,
- $handler->subtask,
- $handler_id,
- ),
- '#key' => 'panels',
- '#member_of' => 'context providers',
- ) + $provider_map[$handler->task];
- }
- }
- }
-}
diff --git a/modules/authcache_panels/authcache_panels.info b/modules/authcache_panels/authcache_panels.info
index 7dd290f..9a84dc3 100644
--- a/modules/authcache_panels/authcache_panels.info
+++ b/modules/authcache_panels/authcache_panels.info
@@ -5,3 +5,4 @@ core = 7.x
dependencies[] = authcache_p13n
dependencies[] = panels
files[] = includes/AuthcachePanelsPaneFragment.inc
+files[] = includes/AuthcachePanelsAbstractDisplayLoader.inc
diff --git a/modules/authcache_panels/authcache_panels.module b/modules/authcache_panels/authcache_panels.module
index fec854e..b53b741 100644
--- a/modules/authcache_panels/authcache_panels.module
+++ b/modules/authcache_panels/authcache_panels.module
@@ -5,50 +5,33 @@
*/
/**
- * Implements hook_authcache_p13n_fragment().
+ * Return TRUE when a valid authcache configuration exists for the given pane.
*/
-function authcache_panels_authcache_p13n_fragment() {
- // Construct a list of displays together with context providers necessary to
- // load them.
- $base_fragment_groups = module_invoke_all('authcache_panels_base_fragments');
- drupal_alter('authcache_panels_base_fragments', $base_fragment_groups);
-
- foreach ($base_fragment_groups as $base_fragments) {
- $displays = panels_load_displays(array_keys($base_fragments));
-
- $fragments = array();
- foreach ($displays as $did => $display) {
- foreach ($display->content as $pid => $pane) {
- $config = _authcache_panels_pane_get_options($pane);
-
- if (!empty($config['status'])) {
- $config += authcache_p13n_config_defaults();
- $fragment_id = "panels/$did/$pid";
- $granularity = authcache_p13n_config_cache_granularity($config);
- $fragments[$fragment_id] = array(
- 'fragment' => array(
- '#class' => 'AuthcachePanelsPaneFragment',
- '#arguments' => array($did, $pid),
- ),
- 'bootstrap phase' => DRUPAL_BOOTSTRAP_FULL,
- 'cache maxage' => authcache_p13n_config_cache_maxage($config),
- 'cache granularity' => $granularity,
- 'admin name' => t('Pane at position %position on panel %panel', array(
- '%position' => $pane->position,
- '%panel' => $pane->panel,
- )),
- 'admin clients' => $config['clients'],
- );
-
- if (isset($base_fragments[$did])) {
- $fragments[$fragment_id] += $base_fragments[$did];
- }
- }
- }
- }
- }
+function authcache_panels_pane_fragment_enabled($pane) {
+ $config = _authcache_panels_pane_get_options($pane);
+ $fragment_id = authcache_panels_pane_fragment_id($pane);
+ return (!empty($config['status']) && $fragment_id);
+}
- return $fragments;
+/**
+ * Return fragment renderer for the given panel pane.
+ */
+function authcache_panels_pane_fragment($pane) {
+ $config = _authcache_panels_pane_get_options($pane);
+ $granularity = authcache_p13n_config_cache_granularity($config);
+ return array(
+ 'fragment' => array(
+ '#class' => 'AuthcachePanelsPaneFragment',
+ ),
+ 'bootstrap phase' => DRUPAL_BOOTSTRAP_FULL,
+ 'cache maxage' => authcache_p13n_config_cache_maxage($config),
+ 'cache granularity' => $granularity,
+ 'admin name' => t('Pane at position %position on panel %panel', array(
+ '%position' => $pane->position,
+ '%panel' => $pane->panel,
+ )),
+ 'admin clients' => $config['clients'],
+ );
}
/**
@@ -64,24 +47,20 @@ function authcache_panels_ctools_plugin_directory($module, $plugin) {
* Implements hook_panels_pane_content_alter().
*/
function authcache_panels_panels_pane_content_alter($content, $pane, $args, $context, $renderer, $display) {
- if (authcache_page_is_cacheable()) {
+ if (authcache_page_is_cacheable() && authcache_panels_pane_fragment_enabled($pane)) {
$config = _authcache_panels_pane_get_options($pane);
- if (!empty($config['status'])) {
- $fragment_id = "panels/{$display->did}/{$pane->pid}";
-
- $fragment = array(
- '#theme' => 'authcache_p13n_fragment',
- '#fragment' => $fragment_id,
- '#clients' => $config['clients'],
- '#fallback' => $config['fallback'],
- );
+ $fragment = array(
+ '#theme' => 'authcache_p13n_fragment',
+ '#fragment' => authcache_panels_pane_fragment_id($pane),
+ '#clients' => $config['clients'],
+ '#fallback' => $config['fallback'],
+ );
- $element = array('#markup' => $content->content);
- authcache_p13n_attach($element, $fragment);
+ $element = array('#markup' => $content->content);
+ authcache_p13n_attach($element, $fragment);
- $content->content = render($element);
- }
+ $content->content = render($element);
}
}
@@ -96,9 +75,55 @@ function authcache_panels_panels_display_save($display) {
* Return options for the given pane.
*/
function _authcache_panels_pane_get_options($pane) {
- if (empty($pane->cache) || $pane->cache['method'] != 'authcache_panels') {
- return;
+ if (!empty($pane->cache) && $pane->cache['method'] == 'authcache_panels') {
+ return $pane->cache['settings']['authcache'] + authcache_p13n_config_defaults();
}
- return $pane->cache['settings']['authcache'];
+ return FALSE;
+}
+
+/**
+ * Return a fragment id for the given pane.
+ */
+function authcache_panels_pane_fragment_id($pane) {
+ if (!empty($pane->cache) && $pane->cache['method'] == 'authcache_panels') {
+ return 'panels/' . str_replace('_', '-', $pane->cache['settings']['machine_name']);
+ }
+
+ return FALSE;
+}
+
+/**
+ * Given a pane, generate an initial machine name.
+ */
+function authcache_panels_pane_machine_name_generate($display, $pid) {
+ ctools_include('content');
+
+ $suffix = '';
+ for ($attempt = 0; $attempt < 100; $attempt++) {
+ $pane = $display->content[$pid];
+ $content_type = ctools_get_content_type($pane->type);
+ $title = ctools_content_admin_title($content_type, $pane->subtype, $pane->configuration, $display->context);
+ if (!$title) {
+ $title = t('Deleted/missing content type @type', array('@type' => $pane->type));
+ }
+
+ if ($attempt > 0) {
+ $suffix = '-' . $attempt;
+ }
+
+ $machine_name = preg_replace('/[^a-z0-9-]+/', '_', strtolower($title));
+ $machine_name = substr($machine_name, 0, 64 - strlen($suffix)) . $suffix;
+
+ if (!authcache_panels_pane_machine_name_exists($machine_name)) {
+ return $machine_name;
+ }
+ }
+}
+
+/**
+ * Return TRUE if the given machine name exists.
+ */
+function authcache_panels_pane_machine_name_exists($machine_name) {
+ return authcache_p13n_request_exists('frag/panels/' . str_replace('_', '-', $machine_name));
}
diff --git a/modules/authcache_panels/includes/AuthcachePanelsAbstractDisplayLoader.inc b/modules/authcache_panels/includes/AuthcachePanelsAbstractDisplayLoader.inc
new file mode 100644
index 0000000..0717f65
--- /dev/null
+++ b/modules/authcache_panels/includes/AuthcachePanelsAbstractDisplayLoader.inc
@@ -0,0 +1,58 @@
+paneId = $pane_id;
+ }
+
+ /**
+ * Load the display object.
+ */
+ protected abstract function loadDisplay();
+
+ /**
+ * {@inheritdoc}
+ */
+ public function load($params, $context) {
+ ctools_include('plugins', 'panels');
+ ctools_include('content');
+
+ $display = $this->loadDisplay();
+
+ if (!$display) {
+ throw new AuthcacheP13nRequestNotFound();
+ }
+
+ if (!isset($display->content[$this->paneId])) {
+ throw new AuthcacheP13nRequestNotFound();
+ }
+
+ // Assign page manager context and arguments prepared by a context
+ // provider.
+ $display->context = array();
+ if (!empty($context['panels']['context'])) {
+ $display->context = $context['panels']['context'];
+ }
+
+ $display->args = array();
+ if (!empty($context['panels']['arguments'])) {
+ $display->args = $context['panels']['arguments'];
+ }
+
+ return array(
+ $this->paneId => $display,
+ );
+ }
+}
diff --git a/modules/authcache_panels/includes/AuthcachePanelsPaneFragment.inc b/modules/authcache_panels/includes/AuthcachePanelsPaneFragment.inc
index 75de209..83d3dc0 100644
--- a/modules/authcache_panels/includes/AuthcachePanelsPaneFragment.inc
+++ b/modules/authcache_panels/includes/AuthcachePanelsPaneFragment.inc
@@ -7,65 +7,13 @@
/**
* Personalization fragment for panel pane.
*/
-class AuthcachePanelsPaneFragment implements AuthcacheP13nFragmentInterface, AuthcacheP13nFragmentLoaderInterface, AuthcacheP13nFragmentAccessInterface {
- protected $displayId;
- protected $paneId;
-
- /**
- * Construct new pane fragment.
- */
- public function __construct($display_id, $pane_id) {
- $this->displayId = $display_id;
- $this->paneId = $pane_id;
- }
-
- /**
- * {@inheritdoc}
- */
- public function load($params, $context) {
- ctools_include('plugins', 'panels');
- ctools_include('content');
-
- $display = panels_load_display($this->displayId);
-
- if (!$display) {
- throw new AuthcacheP13nRequestNotFound();
- }
-
- if (!isset($display->content[$this->paneId])) {
- throw new AuthcacheP13nRequestNotFound();
- }
-
- // Assign page manager context and arguments prepared by a context
- // provider.
- $display->context = array();
- if (!empty($context['panels']['context'])) {
- $display->context = $context['panels']['context'];
- }
-
- $display->args = array();
- if (!empty($context['panels']['arguments'])) {
- $display->args = $context['panels']['arguments'];
- }
-
- // Load renderer.
- $renderer = panels_get_renderer_handler($display->renderer, $display);
- if (!$renderer) {
- throw new AuthcacheP13nRequestNotFound();
- }
-
- return array(
- $this->paneId => $renderer,
- );
- }
-
+class AuthcachePanelsPaneFragment implements AuthcacheP13nFragmentInterface, AuthcacheP13nFragmentAccessInterface {
/**
* {@inheritdoc}
*
* @see panels_renderer_standard::prepare_panes()
*/
- public function check($account, $pane_id, $renderer, $context) {
- $display = $renderer->display;
+ public function check($account, $pane_id, $display, $context) {
$pane = $display->content[$pane_id];
return panels_pane_access($pane, $display);
@@ -76,15 +24,17 @@ class AuthcachePanelsPaneFragment implements AuthcacheP13nFragmentInterface, Aut
*
* @see panels_renderer_standard::render_pane()
*/
- public function render($pane_id, $renderer, $context) {
+ public function render($pane_id, $display, $context) {
$result = '';
- $display = $renderer->display;
- $pane = $display->content[$pane_id];
+ $renderer = panels_get_renderer_handler($display->renderer, $display);
+ if ($renderer) {
+ $pane = $display->content[$pane_id];
- if ($pane->shown) {
- $content = $renderer->render_pane_content($pane);
- $result = render($content->content);
+ if ($pane->shown) {
+ $content = $renderer->render_pane_content($pane);
+ $result = render($content->content);
+ }
}
return $result;
diff --git a/modules/authcache_panels/plugins/cache/authcache_panels.inc b/modules/authcache_panels/plugins/cache/authcache_panels.inc
index f7f4123..f250d34 100644
--- a/modules/authcache_panels/plugins/cache/authcache_panels.inc
+++ b/modules/authcache_panels/plugins/cache/authcache_panels.inc
@@ -16,6 +16,7 @@ $plugin = array(
'settings form submit' => 'authcache_panels_cache_settings_form_submit',
'defaults' => array(
'authcache' => authcache_p13n_config_defaults(),
+ 'machine_name' => NULL,
),
);
@@ -44,6 +45,16 @@ function authcache_panels_cache_clear_cache($display) {
*/
function authcache_panels_cache_settings_form($conf, $display, $pid) {
if ($pid != 'display') {
+ if (!isset($conf['machine_name'])) {
+ $conf['machine_name'] = authcache_panels_pane_machine_name_generate($display, $pid);
+ }
+ $form['machine_name'] = array(
+ '#type' => 'machine_name',
+ '#default_value' => $conf['machine_name'],
+ '#machine_name' => array(
+ 'exists' => 'authcache_panels_pane_machine_name_exists',
+ ),
+ );
$form['authcache'] = array(
'#type' => 'authcache_p13n_config',
'#default_value' => $conf['authcache'],
diff --git a/modules/authcache_panels_page_manager/authcache_panels_page_manager.info b/modules/authcache_panels_page_manager/authcache_panels_page_manager.info
new file mode 100644
index 0000000..cef5bd0
--- /dev/null
+++ b/modules/authcache_panels_page_manager/authcache_panels_page_manager.info
@@ -0,0 +1,6 @@
+name = Authcache Panels by Page Manager
+description = Provide Panels integration when displayed using a Page Manager Task.
+core = 7.x
+dependencies[] = authcache_panels
+dependencies[] = authcache_page_manager
+files[] = includes/AuthcachePanelsPageManagerDisplayLoader.inc
diff --git a/modules/authcache_panels_page_manager/authcache_panels_page_manager.module b/modules/authcache_panels_page_manager/authcache_panels_page_manager.module
new file mode 100644
index 0000000..ad24a2d
--- /dev/null
+++ b/modules/authcache_panels_page_manager/authcache_panels_page_manager.module
@@ -0,0 +1,104 @@
+ t('To add a content pane to the list of personalized items, visit the page manager administration, edit a page, navigate to a panel variant and click on the content tab. Then set up the Authcache caching method on the respective content pane.', array('!page_manager_url' => url('admin/structure/pages'))),
+ );
+}
+
+/**
+ * Implements hook_authcache_p13n_fragment().
+ */
+function authcache_panels_page_manager_authcache_p13n_fragment() {
+ $fragments = array();
+
+ foreach (page_manager_get_tasks_by_type('page') as $task) {
+ $handlers = page_manager_load_task_handlers($task);
+ $fragments += _authcache_panels_page_manager_collect_fragments_from_handlers($handlers);
+
+ foreach (array_keys(page_manager_get_task_subtasks($task)) as $subtask_id) {
+ $handlers = page_manager_load_task_handlers($task, $subtask_id);
+ $fragments += _authcache_panels_page_manager_collect_fragments_from_handlers($handlers);
+ }
+ }
+
+ return $fragments;
+}
+
+/**
+ * Utility function: produce fragment defaults from page manager handler.
+ */
+function _authcache_panels_page_manager_collect_fragments_from_handlers($handlers) {
+ $provider_map = authcache_page_manager_task_context_provider();
+ page_manager_get_task_handler('panel_context');
+
+ $fragments = array();
+ foreach ($handlers as $handler_id => $handler) {
+ if ($handler->handler != 'panel_context') {
+ continue;
+ }
+
+ $display = panels_panel_context_get_display($handler);
+ foreach ($display->content as $pane_id => $pane) {
+ if (!authcache_panels_pane_fragment_enabled($pane)) {
+ continue;
+ }
+
+ // Get panel pane base fragment.
+ $fragment_id = authcache_panels_pane_fragment_id($pane);
+ $fragment = authcache_panels_pane_fragment($pane);
+
+ // Add fragment loader and admin entry.
+ $fragment += array(
+ 'fragment loader' => array(
+ '#class' => 'AuthcachePanelsPageManagerDisplayLoader',
+ '#arguments' => array(
+ $pane_id,
+ $handler->task,
+ $handler->subtask,
+ $handler_id,
+ ),
+ ),
+ 'admin group' => t('Panels (by Page Manager)'),
+ 'admin entry object' => array(
+ '#class' => 'AuthcachePageManagerAdminEntry',
+ '#arguments' => array(
+ $handler->task,
+ $handler->subtask,
+ $handler_id,
+ '@admin clients',
+ '@admin entry',
+ ),
+ ),
+ );
+
+ // Add context provider entry.
+ if (!empty($provider_map[$handler->task])) {
+ $context_provider = array(
+ '#arguments' => array(
+ $handler->task,
+ $handler->subtask,
+ $handler_id,
+ ),
+ '#key' => 'panels',
+ '#member_of' => 'context providers',
+ );
+
+ $fragment += array(
+ 'panels context provider' => $context_provider + $provider_map[$handler->task],
+ );
+ }
+
+ $fragments[$fragment_id] = $fragment;
+ }
+ }
+
+ return $fragments;
+}
diff --git a/modules/authcache_panels_page_manager/includes/AuthcachePanelsPageManagerDisplayLoader.inc b/modules/authcache_panels_page_manager/includes/AuthcachePanelsPageManagerDisplayLoader.inc
new file mode 100644
index 0000000..102ba40
--- /dev/null
+++ b/modules/authcache_panels_page_manager/includes/AuthcachePanelsPageManagerDisplayLoader.inc
@@ -0,0 +1,36 @@
+taskId = $task_id;
+ $this->subtaskId = $subtask_id;
+ $this->handlerId = $handler_id;
+ }
+
+ /**
+ * Load the display object.
+ */
+ protected function loadDisplay() {
+ $task = page_manager_get_task($this->taskId);
+ $handlers = page_manager_load_task_handlers($task, $this->subtaskId);
+ $handler = $handlers[$this->handlerId];
+ page_manager_get_task_handler('panel_context');
+ return panels_panel_context_get_display($handler);
+ }
+}