style_plugin->options; $handler = $view->style_plugin; $fields = &$view->field; $columns = $handler->sanitize_columns($options['columns'], $fields); $active = !empty($handler->active) ? $handler->active : ''; $order = !empty($handler->order) ? $handler->order : 'asc'; $query = tablesort_get_querystring(); if ($query) { $query = '&'. $query; } // Fields must be rendered in order as of Views 2.3, so we will pre-render // everything. $renders = array(); $keys = array_keys($view->field); foreach ($result as $count => $row) { foreach ($keys as $id) { $renders[$count][$id] = $view->field[$id]->theme($row); } } foreach ($columns as $field => $column) { // render the header labels if ($field == $column && empty($fields[$field]->options['exclude'])) { $label = check_plain(!empty($fields[$field]) ? $fields[$field]->label() : ''); if (empty($options['info'][$field]['sortable']) || !$fields[$field]->click_sortable()) { $vars['header'][$field] = $label; } else { // @todo -- make this a setting $initial = 'asc'; if ($active == $field && $order == 'asc') { $initial = 'desc'; } $title = t('sort by @s', array('@s' => $label)); if ($active == $field) { $label .= theme('tablesort_indicator', $initial); } $link_options = array( 'html' => TRUE, 'attributes' => array('title' => $title), 'query' => 'order='. urlencode($field) .'&sort='. $initial . $query, ); $vars['header'][$field] = l($label, $_GET['q'], $link_options); } } // Create a second variable so we can easily find what fields we have and what the // CSS classes should be. $vars['fields'][$field] = views_css_safe($field); if ($active == $field) { $vars['fields'][$field] .= ' active'; } // Render each field into its appropriate column. foreach ($result as $num => $row) { if (!empty($fields[$field]) && empty($fields[$field]->options['exclude'])) { $field_output = $renders[$num][$field]; // Don't bother with separators and stuff if the field does not show up. if (!isset($field_output) && isset($vars['rows'][$num][$column])) { continue; } // Place the field into the column, along with an optional separator. if (isset($vars['rows'][$num][$column])) { if (!empty($options['info'][$column]['separator'])) { $vars['rows'][$num][$column] .= filter_xss_admin($options['info'][$column]['separator']); } } else { $vars['rows'][$num][$column] = ''; } $vars['rows'][$num][$column] .= $field_output; } } } foreach ($vars['rows'] as $num => $row) { $vars['row_classes'][$num][] = ($num % 2 == 0) ? 'odd' : 'even'; } $vars['class'] = 'views-table'; if (!empty($options['sticky'])) { drupal_add_js('misc/tableheader.js'); $vars['class'] .= " sticky-enabled"; } // Draggableviews output begin $info = $view->draggableviews_info; if (!isset($info['order'])) return; // loop through all rows the view returned foreach ($vars['rows'] as $i => $row) { $nid = $result[$i]->{$view->base_field}; // build indentation (as tabledrag requires) $indentation = theme('indentation', $info['nodes'][$nid]['depth']); // get node object switch ($view->base_table) { case 'users': $node = user_load($nid); break; case 'node': $node = node_load(array('nid' => $nid)); break; } if (strcmp($view->base_table, 'node') == 0) { if (isset($info['types'][$node->type])) { // set node type specification, if available (e.g. tabledrag-root) $vars['tabledrag_type'][$i] = 'tabledrag-'. $info['types'][$node->type]; } } // Tabledrag needs all concerned fields to be input elements. // The values of the input elements will be changed by tabledrag while // dragging the rows. As we want to use these values we need to // give them names. // // Concerned fields are // *) the order field // *) the parent field (if hierarchy is used) // This for loop should prevent copy->paste'ing code. foreach (array('hierarchy', 'order') AS $modus) { if (isset($info[$modus])) { if ($modus == 'hierarchy') { $value = $info['nodes'][$nid]['parent']; // get the field that should be rendered $field = &$info['hierarchy']['field']; } else { // get depth of current field $depth = $info['nodes'][$nid]['depth']; $value = $info['nodes'][$nid]['order'][$depth]; // get the field that should be rendered $field = &$info['order']['field']; } // Get the form element. $form_element = $field['handler']->get_form_element($value, array('field_name' => $field['field_name'] .'_'. $nid, 'class' => $field['field_name'])); // Render the new form element. $vars['rows'][$i][$field['field_name']] = drupal_render($form_element); if (!user_access('Allow Reordering') || $info['locked']) { // The tabledrag js would hide the input fields (depending on the settings). But the // tabledrag js will not be added (either because of missing permissions or because // the hierarchy is locked), so we have to hide the input fields on our own. if (!$info[$modus]['visible']) { $vars['style'][$field['field_name']] = 'display: none;'; } } } } if (isset($info['hierarchy'])) { // Put indentation in front of first field and append rendered hidden node id // that we need for tabledrag and expand/collapse. $hidden_nid = array( '#type' => 'hidden', '#name' => 'hidden_nid', '#value' => $nid, '#attributes' => array('class' => 'hidden_nid'), ); $key = key($vars['rows'][$i]); $vars['rows'][$i][$key] = $indentation . $vars['rows'][$i][$key] . drupal_render($hidden_nid); } // Mark extended nodes. if ($info['nodes'][$nid]['extension'] == TRUE) { $vars['draggableviews_extended'][$i] = TRUE; } // Let extension modules alter the output. foreach (module_implements('draggableviews_row_alter') as $module) { $function = $module .'_draggableviews_row_alter'; $function($vars['rows'][$i], $nid, $info, $view); } } // Output data. $vars['tabledrag_table_id'] = 'draggableview_'. $view->name .'_'. $vars['id']; if (user_access('Allow Reordering') && !$info['locked']) { // Prepare tabledrag settings for output. $tabledrag = array(); if (isset($info['order'])) { $tabledrag[] = array( 'action' => 'order', 'relationship' => 'sibling', 'source' => $info['order']['field']['field_name'], 'group' => $info['order']['field']['field_name'], 'subgroup' => $info['order']['field']['field_name'], 'hidden' => !$info['order']['visible'], 'limit' => 0, ); } if (isset($info['hierarchy'])) { $tabledrag[] = array( 'action' => 'match', 'relationship' => 'parent', 'source' => 'hidden_nid', 'group' => $info['hierarchy']['field']['field_name'], 'subgroup' => $info['hierarchy']['field']['field_name'], 'hidden' => !$info['hierarchy']['visible'], 'limit' => $info['depth_limit'], ); } // Add tabledrag behavior. foreach ($tabledrag as $drag) { drupal_add_tabledrag($vars['tabledrag_table_id'], $drag['action'], $drag['relationship'], $drag['group'], $drag['subgroup'], $drag['source'], $drag['hidden'], $drag['limit']); } } if (isset($info['hierarchy'])) { // Fetch expand information from database. $uid = $info['expand_links']['by_uid'] ? $user->uid : 0; $result = db_query("SELECT parent_nid, collapsed FROM {draggableviews_collapsed} WHERE uid=%d AND view_name='%s'", $uid, $view->name); $states = array(); while ($state = db_fetch_object($result)) { $states[$state->parent_nid] = $state->collapsed; } // Check if "expand" links should be shown. if ($info['expand_links']['show']) { drupal_add_js(drupal_get_path('module', 'draggableviews') .'/draggableviews.js'); // Let javascript know about the parent field. drupal_add_js(array( 'draggableviews' => array( $vars['tabledrag_table_id'] => array( 'parent' => $info['hierarchy']['field']['field_name'], ), ), ), 'setting'); if (empty($states)) { // let js know whether child nodes should be expanded or not drupal_add_js(array( 'draggableviews' => array( $vars['tabledrag_table_id'] => array( 'expand_default' => $options['tabledrag_expand']['collapsed'] ? 1 : 0, 'states' => array(), ), ), ), 'setting'); } else { drupal_add_js(array( 'draggableviews' => array( $vars['tabledrag_table_id'] => array( 'states' => $states, ), ), ), 'setting'); } } } drupal_add_css(drupal_get_path('module', 'draggableviews') .'/styles.css'); } function template_preprocess_draggableviews_view_draggabletable_form($vars) { // Get style plugin. $style_plugin = $vars['form']['#parameters'][2]; // Get structured info array. $info = $style_plugin->view->draggableviews_info; $vars['view'] = theme($style_plugin->theme_functions(), $style_plugin->view, $style_plugin->options, $style_plugin->view->result, ''); // Don't render the submit form.. // - if user has no access or // - if structure is locked. if (user_access('Allow Reordering') && !$info['locked']) { $vars['form'] = drupal_render($vars['form']); } else { $vars['form'] = ''; } } /** * Theme the form for the table style plugin */ function theme_draggableviews_ui_style_plugin_draggabletable($form) { // the following lines are copied from the table style plugin /* COPY BEGIN */ $output = drupal_render($form['description_markup']); $header = array( t('Field'), t('Column'), t('Separator'), array( 'data' => t('Sortable'), 'align' => 'center', ), array( 'data' => t('Default sort'), 'align' => 'center', ), ); $rows = array(); foreach (element_children($form['columns']) as $id) { $row = array(); $row[] = drupal_render($form['info'][$id]['name']); $row[] = drupal_render($form['columns'][$id]); $row[] = drupal_render($form['info'][$id]['separator']); if (!empty($form['info'][$id]['sortable'])) { $row[] = array( 'data' => drupal_render($form['info'][$id]['sortable']), 'align' => 'center', ); $row[] = array( 'data' => drupal_render($form['default'][$id]), 'align' => 'center', ); } else { $row[] = ''; $row[] = ''; } $rows[] = $row; } // Add the special 'None' row. $rows[] = array(t('None'), '', '', '', array('align' => 'center', 'data' => drupal_render($form['default'][-1]))); $output .= theme('table', $header, $rows); /* COPY END */ // Render Draggable view settings // The following lines add the new output from draggableviews // Build order table. $tabledrag_order_columns = array(); $tabledrag_order_columns[] = 'Order Field:'; foreach (element_children($form['tabledrag_order']) AS $col) { $tabledrag_order_columns[] = drupal_render($form['tabledrag_order'][$col]); } $tabledrag_order_visible = drupal_render($form['tabledrag_order_visible']); $description_order = drupal_render($form['tabledrag_description_order']); // Build hierarchy table. $tabledrag_hierarchy_columns = array(); $tabledrag_hierarchy_columns[] = 'Parent:'; foreach (element_children($form['tabledrag_hierarchy']) AS $col) { $tabledrag_hierarchy_columns[] = drupal_render($form['tabledrag_hierarchy'][$col]); } $tabledrag_hierarchy_visible = drupal_render($form['tabledrag_hierarchy_visible']); $description_hierarchy = drupal_render($form['tabledrag_description_hierarchy']); $draggableviews_depth_limit = drupal_render($form['draggableviews_depth_limit']); // build types table $tabledrag_types_rows = array(); foreach (element_children($form['tabledrag_types']) AS $id) { $columns = array(); foreach (element_children($form['tabledrag_types'][$id]) AS $col) { $columns[] = drupal_render($form['tabledrag_types'][$id][$col]); } $tabledrag_types_rows[] = $columns; } $tabledrag_types_add = drupal_render($form['tabledrag_types_add']); $description_types = drupal_render($form['tabledrag_description_types']); $tabledrag_expand = drupal_render($form['tabledrag_expand']); $draggableviews_extensions = drupal_render($form['draggableviews_extensions']); $description_extensions = drupal_render($form['draggableviews_description_extensions']); $tabledrag_lock = drupal_render($form['tabledrag_lock']); $description_tabledrag_lock = drupal_render($form['description_tabledrag_lock']); $draggableviews_default_on_top = drupal_render($form['draggableviews_default_on_top']); $draggableviews_arguments = drupal_render($form['draggableviews_arguments']); // Let extension modules append to the output $extensions = array(); foreach (module_implements('draggableviews_style_plugin_render') as $module) { $function = $module .'_draggableviews_style_plugin_render'; $extensions[] = $function($form); } // append form data left to output // all items that have not been rendered until this point // will be rendered now. So we can seperate the settings we // inherited from plugin_table from plugin_draggableviews settings. $output .= drupal_render($form); // Append order settings. $output .= $tabledrag_header; $output .= $description_tabledrag; $output .= $description_order; $output .= theme('table', array(' ', t('Field'), t('Handler')), array($tabledrag_order_columns)); $output .= $tabledrag_order_add; $output .= $tabledrag_order_visible; // Append hierarchy settings. $output .= theme('table', array(' ', t('Field'), t('Handler')), array($tabledrag_hierarchy_columns)); $output .= $description_hierarchy; $output .= $tabledrag_hierarchy_visible; // Append depth limit textfield to output. $output .= $draggableviews_depth_limit; if (strcmp($form['#base_table'], 'node') == 0) { // Append tabledrag types settings. $output .= $description_types; $output .= theme('table', array(t('Node type'), t('Type'), ' '), $tabledrag_types_rows); $output .= $tabledrag_types_add; } // Append expand yes/no checkbox to output. $output .= $tabledrag_expand; $output .= $tabledrag_expand_default; // Append page extensions output. $output .= $description_extensions; $output .= $draggableviews_extensions; // Append lock output. $output .= $description_tabledrag_lock; $output .= $tabledrag_lock; // Append default behaviour radios. $output .= $draggableviews_default_on_top; // Append argument checkbox. $output .= $draggableviews_arguments; // append extension modules output $output .= implode('', $extensions); // return output return $output; }