diff --git a/views_content/plugins/content_types/views.inc b/views_content/plugins/content_types/views.inc index 93f14c6..a9590bf 100644 --- a/views_content/plugins/content_types/views.inc +++ b/views_content/plugins/content_types/views.inc @@ -11,6 +11,8 @@ if (variable_get('ctools_content_all_views', TRUE)) { 'defaults' => array( 'override_pager_settings' => FALSE, 'use_pager' => FALSE, + 'set_view_mode' => FALSE, + 'set_style_plugin' => FALSE, 'nodes_per_page' => 10, 'pager_id' => 0, 'offset' => 0, @@ -369,6 +371,22 @@ function views_content_views_content_type_edit_form($form, &$form_state) { '#dependency' => array('override-pager-checkbox' => array(1)), ); + if ($view->display_handler->get_option('row_plugin') == 'entity') { + $form['set_view_mode'] = array( + '#type' => 'checkbox', + '#title' => t('Set view mode'), + '#default_value' => $conf['set_view_mode'], + '#description' => t('Select this to expose view mode choice.'), + ); + } + + $form['set_style_plugin'] = array( + '#type' => 'checkbox', + '#title' => t('Set style plugin'), + '#default_value' => $conf['set_style_plugin'], + '#description' => t('Select this to expose style plugin choice.'), + ); + $form['panel_args'] = array( '#type' => 'checkbox', '#title' => t('Send arguments'), diff --git a/views_content/plugins/content_types/views_panes.inc b/views_content/plugins/content_types/views_panes.inc index b77404e..47c29ef 100644 --- a/views_content/plugins/content_types/views_panes.inc +++ b/views_content/plugins/content_types/views_panes.inc @@ -262,6 +262,22 @@ function views_content_views_panes_content_type_render($subtype, $conf, $panel_a $view->display_handler->set_option('pager', $pager); } + if (in_array($view->display_handler->get_option('row_plugin'), array('node', 'entity'))) { + if ($allow['set_view_mode']) { + if ($conf['view_mode']) { + $row_options = $view->display_handler->get_option('row_options'); + $row_options['view_mode'] = $conf['view_mode']; + $row_options['links'] = $conf['links']; + $row_options['comments'] = $conf['comments']; + $view->display_handler->set_option('row_options', $row_options); + } + } + } + + if ($allow['set_style_plugin']) { + $view->display_handler->set_option('style_plugin', $conf['style_plugin']); + } + if ($allow['fields_override']) { if ($conf['fields_override']) { $fields = $view->get_items('field'); @@ -310,12 +326,18 @@ function views_content_views_panes_content_type_render($subtype, $conf, $panel_a */ function views_content_views_panes_add_defaults(&$conf, $view) { $pager = $view->display_handler->get_option('pager'); + $row_options = $view->display_handler->get_option('row_options'); + $display_options = $view->display_handler->get_option('display_options'); $conf += array( 'link_to_view' => $view->display_handler->get_option('link_to_view'), 'more_link' => $view->display_handler->get_option('more_link'), 'feed_icons' => FALSE, 'use_pager' => $pager['type'] != 'none' && $pager['type'] != 'some', + 'view_mode' => isset($row_options['view_mode']) ? $row_options['view_mode'] : 'full', + 'links' => isset($row_options['links']) ? $row_options['links'] : FALSE, + 'comments' => isset($row_options['comments']) ? $row_options['comments'] : FALSE, + 'style_plugin' => isset($display_options['style_plugin']) ? $display_options['style_plugin'] : FALSE, 'pager_id' => isset($pager['options']['id']) ? $pager['options']['id'] : 0, 'items_per_page' => !empty($pager['options']['items_per_page']) ? $pager['options']['items_per_page'] : 10, 'offset' => !empty($pager['options']['offset']) ? $pager['options']['offset'] : 0, @@ -432,6 +454,69 @@ function views_content_views_panes_content_type_edit_form($form, &$form_state) { '#suffix' => '', ); } + + if ($allow['set_view_mode']) { + // This is assuming too much. A better way to do this? + // Ideally just use the options_form method from the plugin. + $base_table = $view->display_handler->view->base_table; + // Check if is a valid entity type. + $entity_types = entity_get_info(); + + if (isset($entity_types[$base_table])) { + $view_modes = array_keys($entity_types[$base_table]['view modes']); + $options = array_combine($view_modes, $view_modes); + } + else { + // Default to node + $entity_info = entity_get_info('node'); + $view_modes = array_keys($entity_info['view modes']); + $options = array_combine($view_modes, $view_modes); + } + + + $options = array(); + if (isset($entity_types[$base_table])) { + foreach ($entity_types[$base_table]['view modes'] as $mode => $settings) { + $options[$mode] = $settings['label']; + } + } + else { + // Default to node + $entity_info = entity_get_info('node'); + foreach ($entity_info['view modes'] as $mode => $settings) { + $options[$mode] = $settings['label']; + } + } + + // @see views_plugin_row_node_view::options_form() + $form['view_mode'] = array( + '#type' => 'select', + '#title' => t('Select view mode'), + '#default_value' => $conf['view_mode'], + '#options' => $options, + ); + $form['links'] = array( + '#type' => 'checkbox', + '#title' => t('Display links'), + '#default_value' => $conf['links'], + ); + $form['comments'] = array( + '#type' => 'checkbox', + '#title' => t('Display comments'), + '#default_value' => $conf['comments'], + ); + } + + if ($allow['set_style_plugin']) { + $options = views_fetch_plugin_names('style', $view->display_handler->get_style_type(), array($view->display_handler->view->base_table)); + $form['style_plugin'] = array( + '#type' => 'select', + '#title' => t('Select style plugin'), + '#default_value' => $conf['style_plugin'], + '#options' => $options, + ); + } + if ($allow['items_per_page']) { $form['items_per_page'] = array( '#type' => 'textfield', @@ -550,7 +635,7 @@ function views_content_views_panes_content_type_edit_form($form, &$form_state) { */ function views_content_views_panes_content_type_edit_form_submit(&$form, &$form_state) { // Copy everything from our defaults. - $keys = array('link_to_view', 'more_link', 'feed_icons', 'use_pager', + $keys = array('link_to_view', 'more_link', 'feed_icons', 'use_pager', 'view_mode', 'links', 'comments', 'style_plugin', 'pager_id', 'items_per_page', 'offset', 'path_override', 'path', 'arguments', 'fields_override', 'exposed'); foreach ($keys as $key) { diff --git a/views_content/plugins/views/views_content_plugin_display_panel_pane.inc b/views_content/plugins/views/views_content_plugin_display_panel_pane.inc index e02f896..a97983b 100644 --- a/views_content/plugins/views/views_content_plugin_display_panel_pane.inc +++ b/views_content/plugins/views/views_content_plugin_display_panel_pane.inc @@ -26,6 +26,8 @@ class views_content_plugin_display_panel_pane extends views_plugin_display { $options['allow'] = array( 'contains' => array( 'use_pager' => array('default' => FALSE), + 'set_view_mode' => array('default' => FALSE), + 'set_style_plugin' => array('default' => FALSE), 'items_per_page' => array('default' => FALSE), 'offset' => array('default' => FALSE), 'link_to_view' => array('default' => FALSE), @@ -160,6 +162,8 @@ class views_content_plugin_display_panel_pane extends views_plugin_display { $options = array( 'use_pager' => t('Use pager'), + 'set_view_mode' => t('Set view mode'), + 'set_style_plugin' => t('Set style plugin'), 'items_per_page' => t('Items per page'), 'offset' => t('Pager offset'), 'link_to_view' => t('Link to view'),