Last active
August 29, 2015 14:08
-
-
Save paullinney/7e62dc94a73c0af8623d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add a node, using a panel node template override, into Search index | |
* - search_api | |
* - search_api_solr | |
*/ | |
/** | |
* Implements hook_entity_property_info_alter(). | |
*/ | |
function MY_SEARCH_entity_property_info_alter(&$info) { | |
$info['node']['properties']['panel_node'] = array( | |
'type' => 'text', | |
'label' => t('Panel Node Render'), | |
'sanitized' => TRUE, | |
'getter callback' => 'MY_SEARCH_panel_node_getter_callback', | |
); | |
} | |
function MY_SEARCH_panel_node_getter_callback($node) { | |
$nodes_list = MY_SEARCH_panel_nodes_list(); | |
if (in_array($node->type, $nodes_list)) { | |
// @see http://drupal.stackexchange.com/questions/47731/how-to-print-a-panel-page | |
$task = page_manager_get_task('node_view'); | |
// Load the node into a context. | |
ctools_include('context'); | |
ctools_include('context-task-handler'); | |
$contexts = ctools_context_handler_get_task_contexts($task, '', array($node)); | |
$output = ctools_context_handler_render($task, '', $contexts, array($node->nid)); | |
if ($output !== FALSE) { | |
if (is_array($output)) { | |
$content = $output['content']; | |
return drupal_render($content); | |
} | |
else { | |
return $output; | |
} | |
} | |
// Otherwise, fall back. | |
return drupal_render(node_view(node_load($node->nid))); | |
} | |
return NULL; | |
} | |
function MY_SEARCH_panel_nodes_list() { | |
return array( | |
'A_CONTENT_TYPE', | |
'A_CONTENT_TYPE_2' | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment