danielebarchiesi@2: 'default'); danielebarchiesi@2: $options['tab_title_field'] = array('default' => NULL); danielebarchiesi@2: danielebarchiesi@2: return $options; danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: // Create the options form. danielebarchiesi@2: function options_form(&$form, &$form_state) { danielebarchiesi@2: parent::options_form($form, $form_state); danielebarchiesi@2: $options = array(); danielebarchiesi@2: $styles = module_invoke_all('quicktabs_tabstyles'); danielebarchiesi@2: // The keys used for options must be valid html id-s. danielebarchiesi@2: // Removing the css file path, because that can't be used. danielebarchiesi@2: foreach ($styles as $style) { danielebarchiesi@2: $options[$style] = $style; danielebarchiesi@2: } danielebarchiesi@2: ksort($options); danielebarchiesi@2: $form['tab_style'] = array( danielebarchiesi@2: '#type' => 'select', danielebarchiesi@2: '#title' => t('Tab style'), danielebarchiesi@2: '#options' => array('nostyle' => t('No style'), 'default' => t('Default style')) + $options, danielebarchiesi@2: '#default_value' => $this->options['tab_style'], danielebarchiesi@2: '#description' => t('The tab style that will be applied to this set of tabs. Note that this style may not show in the live preview.'), danielebarchiesi@2: '#weight' => -5, danielebarchiesi@2: ); danielebarchiesi@2: danielebarchiesi@2: if (isset($form['grouping'])) { danielebarchiesi@2: $options = array(); danielebarchiesi@2: foreach (element_children($form['grouping']) as $key => $value) { danielebarchiesi@2: if (!empty($form['grouping'][$key]['field']['#options']) && is_array($form['grouping'][$key]['field']['#options'])) { danielebarchiesi@2: $options = array_merge($options, $form['grouping'][$key]['field']['#options']); danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: unset($options['']); danielebarchiesi@2: $form['tab_title_field'] = array( danielebarchiesi@2: '#type' => 'select', danielebarchiesi@2: '#title' => t('Title field'), danielebarchiesi@2: '#options' => $options, danielebarchiesi@2: '#required' => TRUE, danielebarchiesi@2: '#default_value' => $this->options['tab_title_field'], danielebarchiesi@2: '#description' => t('Select the field that will be used as the tab title.'), danielebarchiesi@2: '#weight' => -3, danielebarchiesi@2: ); danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: // Ensure we have all the settings necessary to render into tabs. danielebarchiesi@2: function validate() { danielebarchiesi@2: $errors = parent::validate(); danielebarchiesi@2: danielebarchiesi@2: // Ensure that we're using the field row style. danielebarchiesi@2: if (!$this->row_plugin->uses_fields()) { danielebarchiesi@2: $errors[] = t('Display "@display" uses the "@style" row style, but the Quicktabs display style requires use of the "Fields" row style.', array('@display' => $this->display->display_title, '@style' => $this->row_plugin->definition['title'])); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: // Ensure that a valid tab title field is selected. danielebarchiesi@2: $fields = $this->display->handler->get_handlers('field'); danielebarchiesi@2: if (empty($this->options['tab_title_field']) || !isset($fields[$this->options['tab_title_field']])) { danielebarchiesi@2: $errors[] = t('The Quicktabs display style requires that a field be configured to be used as the tab title.'); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: return $errors; danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: // Override the render functionality. danielebarchiesi@2: function render() { danielebarchiesi@2: if (empty($this->row_plugin)) { danielebarchiesi@2: vpr('views_plugin_style_default: Missing row plugin'); danielebarchiesi@2: return; danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: $view = $this->view; danielebarchiesi@2: $qt_name = 'view__' . $view->name .'__'. $view->current_display; danielebarchiesi@2: danielebarchiesi@2: // Group the rows according to the grouping field, if specified. danielebarchiesi@2: $sets = $this->render_grouping($this->view->result, $this->options['grouping']); danielebarchiesi@2: $tabs = array(); danielebarchiesi@2: danielebarchiesi@2: foreach ($sets as $title => $records) { danielebarchiesi@2: if ($this->uses_row_plugin()) { danielebarchiesi@2: $rows = array(); danielebarchiesi@2: foreach ($records as $row_index => $row) { danielebarchiesi@2: $this->view->row_index = $row_index; danielebarchiesi@2: $rows[] = $this->row_plugin->render($row); danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: else { danielebarchiesi@2: $rows = $records; danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: // If grouped, we'll be using the group title for each tab. danielebarchiesi@2: if ($this->options['grouping']) { danielebarchiesi@2: danielebarchiesi@2: // Remove labels from titles. danielebarchiesi@2: foreach (element_children($this->options['grouping']) as $key => $value) { danielebarchiesi@2: if (!empty($this->view->field[$this->options['grouping'][$key]['field']]->options['label'])) { danielebarchiesi@2: $title = str_replace($this->view->field[$this->options['grouping'][$key]['field']]->options['label'] . ': ', '', $title); danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: $contents = ''; danielebarchiesi@2: foreach ($rows as $row) { danielebarchiesi@2: $contents .= '
' . $row . '
'; danielebarchiesi@2: } danielebarchiesi@2: $tabs[] = array( danielebarchiesi@2: 'title' => $title, danielebarchiesi@2: 'contents' => array('#markup' => $contents), danielebarchiesi@2: ); danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: // If not grouped, there's just one set of rows that we loop through. danielebarchiesi@2: else { danielebarchiesi@2: foreach ($rows as $index => $row) { danielebarchiesi@2: $title = $this->get_field($index, $this->options['tab_title_field']); danielebarchiesi@2: $tabs[] = array( danielebarchiesi@2: 'title' => $title, danielebarchiesi@2: 'contents' => array('#markup' => $row), danielebarchiesi@2: ); danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: $overrides = array('style' => $view->style_options['tab_style'], 'sorted' => TRUE); danielebarchiesi@2: $quicktabs = quicktabs_build_quicktabs($qt_name, $overrides, $tabs); danielebarchiesi@2: danielebarchiesi@2: $output = drupal_render($quicktabs); danielebarchiesi@2: danielebarchiesi@2: // If doing a live preview, add the JavaScript directly to the output. danielebarchiesi@2: if (isset($view->live_preview) && $view->live_preview) { danielebarchiesi@2: $js = drupal_add_js(); danielebarchiesi@2: $qtsettings = array(); danielebarchiesi@2: foreach ($js['settings']['data'] as $settings) { danielebarchiesi@2: if (isset($settings['quicktabs']['qt_'. $qt_name])) { danielebarchiesi@2: $qtsettings = $settings['quicktabs']['qt_'. $qt_name]; danielebarchiesi@2: break; danielebarchiesi@2: } danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: $output .= "\n"; danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: unset($view->row_index); danielebarchiesi@2: danielebarchiesi@2: return $output; danielebarchiesi@2: } danielebarchiesi@2: danielebarchiesi@2: }