5 * Allow a view context to display individual rows.
9 'title' => t('View row'),
10 'category' => t('View context'),
11 'icon' => 'icon_views_page.png',
12 'description' => t('Display all or a specific amount of rows from a loaded view context.'),
13 'required context' => new ctools_context_required(t('View'), 'view'),
16 'use_fields' => array(),
20 'views_content_views_row_content_type_edit_form' => t('Select context'),
21 'views_content_views_row_edit' => t('Configure rows'),
24 'views_content_views_row_content_type_edit_form' => t('Select context'),
25 'views_content_views_row_edit' => t('Configure rows'),
30 * Render the node_terms content type.
32 function views_content_views_row_content_type_render($subtype, $conf, $panel_args, $context) {
33 if (empty($context) || empty($context->data)) {
37 // Build the content type block.
38 $block = new stdClass();
39 $block->module = 'views_row';
40 $block->delta = $context->argument;
44 // This guarantees the view is rendered normally which must happen.
45 $view = views_content_context_get_view($context);
46 $output = views_content_context_get_output($context);
49 $plugin = $view->style_plugin;
51 // If all rows have to be displayed then simply get the key of all rows.
52 $row_indexes = array();
53 if (empty($conf['rows'])) {
54 if (is_array($output['rows'])) {
55 $row_indexes = array_keys($output['rows']);
59 // If a subset of rows is requested collect the list of row keys.
60 foreach ($conf['rows'] as $index) {
61 $row_indexes[] = $index - 1;
65 if (empty($conf['use_fields']) || empty($plugin->row_plugin)) {
66 foreach ($row_indexes as $row_index) {
67 if (isset($output['rows'][$row_index])) {
68 $sets[$plugin->groups[$row_index]][$row_index] = $output['rows'][$row_index];
73 // If we're using specific fields, go through and poke the 'exclude' flag.
74 foreach ($view->field as $id => $field) {
75 $view->field[$id]->options['exclude'] = empty($conf['fields'][$id]);
78 // Rerender just the rows we need.
79 foreach ($row_indexes as $row_index) {
80 $view->row_index = $row_index;
81 if (!empty($view->result[$view->row_index])) {
82 $sets[$plugin->groups[$view->row_index]][$view->row_index] = $plugin->row_plugin->render($view->result[$view->row_index]);
84 unset($view->row_index);
88 foreach ($sets as $title => $rows) {
89 $block->content .= theme($plugin->theme_functions(),
92 'options' => $plugin->options,
102 function views_content_views_row_content_type_edit_form($form, &$form_state) {
103 // This form does nothing; it exists to let the main form select the view context.
107 function views_content_views_row_content_type_edit_form_submit($form, &$form_state) {
110 function views_content_views_row_edit($form, &$form_state) {
111 $conf = $form_state['conf'];
112 $contexts = $form_state['contexts'];
114 if (empty($contexts[$conf['context']])) {
115 $form['markup'] = array('#markup' => '<p>' . t('Invalid context selected.') . '</p>');
119 if (!isset($contexts[$conf['context']]->argument)) {
120 $name = $contexts[$conf['context']]->placeholder['conf']['name'];
121 list($plugin, $view_data) = explode(':', $name);
122 list($view_name, $display_id) = explode('-', $view_data);
125 $view_data = $contexts[$conf['context']]->argument;
126 list($view_name, $display_id) = explode(':', $view_data);
128 $contexts[$conf['context']]->data['name'] = $view_name;
129 $contexts[$conf['context']]->data['display'] = $display_id;
130 $view = views_content_context_get_view($contexts[$conf['context']]);
132 $form['markup'] = array('#markup' => '<p>' . t('Context contains an invalid view.') . '</p>');
136 ctools_include('dependent');
137 $form['limit_rows'] = array(
138 '#type' => 'checkbox',
139 '#title' => t('Limit rows'),
140 '#default_value' => (int) !empty($conf['rows']),
144 $rows = $view->get_items_per_page();
147 foreach (range(1, $rows) as $row) {
148 $options[$row] = t('Row @number', array('@number' => $row));
150 $form['rows'] = array(
151 '#type' => 'checkboxes',
152 '#title' => t('Select rows'),
153 '#options' => $options,
154 '#default_value' => $conf['rows'],
155 '#dependency' => array('edit-limit-rows' => array(TRUE)),
159 $form['rows'] = array('#markup' => '<p>' . t('The view must have a maximum number of items set to use this setting.') . '</p>');
163 if ($view->display_handler->uses_fields()) {
164 $form['use_fields'] = array(
165 '#type' => 'checkbox',
166 '#title' => t('Display specific fields'),
167 '#default_value' => $conf['use_fields'],
170 $form['fields'] = array(
171 '#type' => 'checkboxes',
172 '#options' => $view->display_handler->get_field_labels(),
173 '#default_value' => $conf['fields'],
174 '#prefix' => '<div id="edit-fields-wrapper"><div id="edit-fields">',
175 '#suffix' => '</div></div>',
176 '#dependency' => array('edit-use-fields' => array(TRUE)),
182 function views_content_views_row_edit_validate(&$form, &$form_state) {
185 function views_content_views_row_edit_submit(&$form, &$form_state) {
186 $form_state['conf']['rows'] = array_filter($form_state['values']['rows']);
187 $form_state['conf']['use_fields'] = $form_state['values']['use_fields'];
188 $form_state['conf']['fields'] = array_filter($form_state['values']['fields']);
191 function views_content_views_row_content_type_admin_info($subtype, $conf, $contexts) {
192 // Go through this route to make sure we catch changes in configuration
194 $plugin = ctools_get_content_type('views_row');
195 $context = ctools_content_select_context($plugin, $subtype, $conf, $contexts);
197 $block = new stdClass();
198 $block->title = t('Row information');
200 if (!empty($conf['use_fields'])) {
201 $display_fields = array();
202 $view = views_content_context_get_view($context);
204 $block->title = t('Broken view');
207 $fields = $view->display_handler->get_field_labels();
209 foreach ($conf['fields'] as $field) {
210 if (!empty($fields[$field])) {
211 $display_fields[$field] = '"<em>' . check_plain($fields[$field]) . '</em>"';
215 if ($display_fields) {
216 $block->content = t('Displaying: !fields', array('!fields' => implode(', ', $display_fields)));
219 $block->content = t('Displaying no fields due to misconfiguration.');
223 $block->content = t('Displaying the configured row.');
229 function views_content_views_row_content_type_admin_title($subtype, $conf, $context) {
230 $rows = array_filter($conf['rows']);
231 $rows = empty($rows) ? t('Show all') : implode(', ', $rows);
232 return format_plural(count($rows),
233 '"@context" row @rows',
234 '"@context" rows @rows',
235 array('@context' => $context->identifier, '@rows' => $rows)