I needed to programmatically render a Ctools Page Manager page that consists of panels. The page required the user
context in order to load the related content.
Below is a short example of how I'm manually rendering the page variant from a custom URL in Drupal 7.
/** * Implements hook_menu(). */ function sample_module_menu() { 'title' => 'Member Profile Preview', 'access callback' => true, 'page callback' => 'sample_module_render_page', ), ); } /** * The menu entry callback for render/user/%/page. * * @param $target_uid * @return array */ function sample_module_render_page($target_uid) { module_load_include('inc', 'ctools', 'page_manager/plugins/tasks/page'); module_load_include('inc', 'ctools', 'includes/context'); $subtask_id = 'page_variant_machine_name'; $page = page_manager_page_load($subtask_id); $task = page_manager_get_task($page->task); $subtask = page_manager_get_task_subtask($task, $subtask_id); $user_context = ctools_context_create('entity:user', user_load($target_uid)); $user_context->id = 'argument_entity_id:user_1'; $user_context->original_argument = $user_context->argument; $user_context->identifier = "User"; $user_context->keyword = "user"; // Turn the contexts into a properly keyed array. ctools_include('context-task-handler'); $output = ctools_context_handler_render($task, $subtask, $contexts, $args); if ($output === FALSE) { return MENU_NOT_FOUND; } return $output; }
Software engineer by profession, embedded systems tinkerer, husband, father, fantasy novel devourer, wine lush, beer and cheese connoisseur