I don't even know if what I want to do is possible, so bear with me. My set-up:
I have a View Context that accepts an author UID argument from the Panel context, and then displays content created by that author UID. This View Context has been added to the user/%user
system Panel in Page Manager. This allows me to create a custom CTools Plugin that takes that View Context, gives it an additional parameter (content type) to filter by, and spit out the final view programmatically.
The purpose of this is to create many small reusable lists of content in different content types that a specific user has authored, with custom more links and other mark-up around those lists. (I.e., we might show 3 of each content type on a profile page, and if they have created more than three, we link to a different user/%user/this-content-type
page that has the full list of that type and a proper pager.) The custom header/footer/more links, the ability to insert additional custom copy or code between lists of nodes, and manual ordering of content types are the main reasons why I'm not simply using Views' default grouping function.
The relevant View rendering code in the CTools Plugin is something like this:
function custom_list_render($subtype, &$conf, $args, $context = NULL) {
$block = new stdClass();
if ($conf['type']) {
$view = views_content_context_get_view($context[0]);
$view_output = views_content_context_get_output($context[0]);
$plugin = $view->style_plugin;
$rows = array();
foreach ($view_output['view']->result as $row_index => $row) {
if (custom_content_type_match_function($row, $conf)) {
$rows[] = $view_output['rows'][$row_index];
}
}
$output = theme($plugin->theme_functions(),
array(
'view' => $view,
'options' => $plugin->options,
'rows' => $rows,
)
);
$block->content = $output;
return $block;
}
This code works. There's some additional admin form work going on that selects and saves the $conf['type']
for each iteration of this plugin that you add to a panel.
Right now, the view output is spit out as rendered entities in a custom view mode. I'm wondering if it's possible to alter the View Context at the plugin level so that when you add this plugin to a panel, you can also select which custom view mode you want the rendered entities to render as. (Think Teaser vs Full vs Block.) If so, at what point do I need to disrupt the view (I imagine before views_content_context_get_view
?) in order to pass it the new view mode, and how?
Alternatively, could I somehow pass an additional custom argument to the view (e.g. "ctools_view_mode" or something) and then use hooks_view_pre_render
to change the view_mode?
Thanks in advance!
Running: Most recent iterations of D7, Panels, Views.
hook_form_views_content_context_view_settings_form_alter()
, I think) so that the user can select the view mode, add a submit handler to store your value somewhere ($form_state['conf'] perhaps) and then implement hook_views_pre_view to swap in the desired view mode. Not making this a real answer since I'm a little light on the details.