You are here

function draggableviews_plugin_style_draggabletable::options_form in DraggableViews 7

Same name and namespace in other branches
  1. 6.3 views/draggableviews_plugin_style_draggabletable.inc \draggableviews_plugin_style_draggabletable::options_form()
  2. 6 draggableviews_plugin_style_draggabletable.inc \draggableviews_plugin_style_draggabletable::options_form()
  3. 6.2 draggableviews_plugin_style_draggabletable.inc \draggableviews_plugin_style_draggabletable::options_form()

Render the given style.

Overrides views_plugin_style_table::options_form

File

views/draggableviews_plugin_style_draggabletable.inc, line 125
Draggableviews style plugin definition.

Class

draggableviews_plugin_style_draggabletable
Style plugin to render each item as a row in a draggable table; Inherits all from views_plugin_table.

Code

function options_form(&$form, &$form_state) {

  // inherit options from style_table
  parent::options_form($form, $form_state);

  // Get field handlers.
  $handlers = $this->display->handler
    ->get_handlers('field');
  if (empty($handlers)) {

    // Can't do anything without fields.
    return;
  }

  // set theme handler
  // theme function is registered in *.module file
  $form['#theme'] = 'draggableviews_ui_style_plugin_draggabletable';

  // DRAGGABLE VIEW OPTIONS
  //
  // + Set field(s) to save the order in
  // + Set field to save the parent in
  // + Apply tabledrag-type to content-types (Root (can't have parent), Leaf (can't have children)).
  // + Set if expand/collapse links should be shown
  // + Toggle tracking of order with respect to View arguments
  // Tell the theme which base_table is beeing used.
  $form['#base_table'] = $this->view->base_table;
  $input = $form_state['input'];

  // Get all system-wide node types as a keyed array.
  foreach (node_type_get_types() as $node_type) {
    $node_types[$node_type->type] = t($node_type->name);
  }

  // Check for input.
  if (!empty($input['style_options'])) {

    // Define the input data as the current data.
    $current = $form_state['input']['style_options'];
  }
  else {

    // Define the already stored data as the current data.
    $current = $this->options;
  }
  $form['tabledrag_header'] = array(
    '#prefix' => '<div style="background: #F6F6F6; border-top: 1px solid #D6DBDE; font-weight: bold; padding: 1em 1em 0;">',
    '#suffix' => '</div>',
    '#value' => t('@display: Style options: Draggable Table Settings', array(
      '@display' => $this->display->display_title,
    )),
  );
  $form['tabledrag_description'] = array(
    '#prefix' => '<div class="description form-item">',
    '#suffix' => '</div>',
    '#value' => t('Within the following section all the <i>Draggable Table</i> settings can be configured. Don\'t be confused by the options above. This style plugin inherits all options that the table style plugin offers.<br />Draggableviews provides two special fields to ease your life. They are called <i>Draggableviews: Order</i> and <i>Draggableviews: Parent</i>. These fields are designed to be used in combination with the "Native" handler.'),
  );
  $form['tabledrag_description_order'] = array(
    '#prefix' => '<div class="description form-item">',
    '#suffix' => '</div>',
    '#value' => t('In order to make rows of a table draggable the order field must be specified.'),
  );
  $form['tabledrag_description_hierarchy'] = array(
    '#prefix' => '<div class="description form-item">',
    '#suffix' => '</div>',
    '#value' => t('Set a parent field if you want to use hierarchies.'),
  );
  $form['tabledrag_description_types'] = array(
    '#prefix' => '<div class="description form-item">',
    '#suffix' => '</div>',
    '#value' => t('You can constrain the user when he drags rows. Type "root" cannot be subordinated. Type "leaf" cannot have child nodes.'),
  );
  $form['draggableviews_description_extensions'] = array(
    '#prefix' => '<div class="description form-item">',
    '#suffix' => '</div>',
    '#value' => t('When you use paging and you want to drag a row from one page to another then you need to show some rows of the previous/next page.'),
  );
  $form['description_tabledrag_lock'] = array(
    '#prefix' => '<div class="description form-item">',
    '#suffix' => '</div>',
    '#value' => t('If you don\'t wan\'t that the hierarchy can be changed use this option.'),
  );
  $options = _draggableviews_filter_fields(array(
    'number',
  ), $handlers);
  $draggableviews_handlers = draggableviews_get_handlers_list();
  $form['tabledrag_order'] = array(
    '#weight' => 9,
    'field' => array(
      '#type' => 'select',
      '#options' => array(
        'none' => '- ' . t('none') . ' -',
      ) + _draggableviews_filter_fields(array(
        'order',
      ), $handlers),
      '#default_value' => $current['tabledrag_order']['field'],
    ),
    'handler' => array(
      '#type' => 'select',
      '#options' => $draggableviews_handlers,
      '#default_value' => $current['tabledrag_order']['handler'],
    ),
  );

  // Show or hide input fields.
  $form['tabledrag_order_visible'] = array(
    '#type' => 'checkboxes',
    '#name' => 'tabledrag_order_visible',
    '#options' => array(
      'visible' => t('Show input fields?'),
    ),
    '#title' => t('Decide whether order input fields should be visible or not'),
    '#default_value' => $current['tabledrag_order_visible'],
  );
  $form['tabledrag_hierarchy'] = array(
    '#weight' => 10,
    'field' => array(
      '#type' => 'select',
      '#options' => array(
        'none' => '- ' . t('none') . ' -',
      ) + _draggableviews_filter_fields(array(
        'nodereference',
      ), $handlers),
      '#default_value' => $current['tabledrag_hierarchy']['field'],
    ),
    'handler' => array(
      '#type' => 'select',
      '#options' => $draggableviews_handlers,
      '#default_value' => $current['tabledrag_hierarchy']['handler'],
    ),
  );

  // Show or hide input fields.
  $form['tabledrag_hierarchy_visible'] = array(
    '#type' => 'checkboxes',
    '#name' => 'tabledrag_hierarchy_visible',
    '#options' => array(
      'visible' => t('Show input fields?'),
    ),
    '#title' => t('Decide whether parent input fields should be visible or not'),
    '#default_value' => $current['tabledrag_hierarchy_visible'],
  );
  $form['draggableviews_depth_limit'] = array(
    '#type' => 'textfield',
    '#size' => 2,
    '#description' => t('Only use this option in combination with hierarchies. Type -1 for no limit.'),
    '#title' => t('Define the depth limit'),
    '#default_value' => $current['draggableviews_depth_limit'],
  );

  // Lock option.
  $form['draggableviews_repair'] = array(
    '#type' => 'checkboxes',
    '#options' => array(
      'repair' => t('Repair broken structures.'),
    ),
    '#description' => t('Uncheck this option if you don\'t want DraggableViews to repair broken structures.'),
    '#title' => t('Structure'),
    '#default_value' => $current['draggableviews_repair'],
  );

  // Ajax handler:
  $form['draggableviews_ajax'] = array(
    '#type' => 'checkbox',
    '#title' => t('Ajax'),
    '#description' => t('If checked and javascript is enabled, the drupal ajax api is used to submit the form.'),
    '#default_value' => $current['draggableviews_ajax'],
  );
  if (strcmp($this->view->base_table, 'node') == 0) {

    // Tabledrag types (root/leaf).
    // These fields will save the behaviour of a node-type (root, leaf).
    $extra_row = isset($input['tabledrag_types_add']) ? TRUE : FALSE;
    for ($i = 0, $index = 0; $i < count($current['tabledrag_types']) + ($extra_row == TRUE ? 1 : 0); $i++) {

      // if option should be deleted, continue loop
      if (isset($input['tabledrag_types_del_' . $i])) {
        continue;
      }
      $form['tabledrag_types'][$index] = array(
        'node_type' => array(
          '#type' => 'select',
          '#options' => $node_types,
          '#default_value' => isset($current['tabledrag_types'][$i]['node_type']) ? $current['tabledrag_types'][$i]['node_type'] : key($node_types),
        ),
        'type' => array(
          '#type' => 'select',
          '#options' => array(
            'root' => 'root',
            'leaf' => 'leaf',
          ),
          '#default_value' => isset($current['tabledrag_types'][$i]['type']) ? $current['tabledrag_types'][$i]['type'] : 'root',
        ),
        'tabledrag_type_del_button' => array(
          '#type' => 'button',
          '#name' => 'tabledrag_types_del_' . $index,
          '#default_value' => t('Delete'),
        ),
      );
      $index++;
    }
  }
  $form['tabledrag_types_add'] = array(
    '#type' => 'button',
    '#name' => 'tabledrag_types_add',
    '#value' => t('Add type'),
  );

  // Expand/collapse options.
  $form['tabledrag_expand'] = array(
    '#type' => 'checkboxes',
    '#name' => 'tabledrag_expand',
    '#options' => array(
      'expand_links' => 'Show expand Links',
      'collapsed' => 'Default is collapsed',
      'by_uid' => 'Unique for each user',
    ),
    '#title' => t('Decide whether expand/collapse links should be shown or not'),
    '#default_value' => $current['tabledrag_expand'],
  );

  // Extensions when using paging.
  $form['draggableviews_extensions'] = array(
    'extension_top' => array(
      '#type' => 'textfield',
      '#size' => 2,
      '#title' => t('How many rows should be displayed of the previous page'),
      '#default_value' => $current['draggableviews_extensions']['extension_top'],
    ),
    'extension_bottom' => array(
      '#type' => 'textfield',
      '#size' => 2,
      '#title' => t('How many rows should be displayed of the next page'),
      '#default_value' => $current['draggableviews_extensions']['extension_bottom'],
    ),
  );

  // Lock option.
  $form['tabledrag_lock'] = array(
    '#type' => 'checkboxes',
    '#name' => 'tabledrag_lock',
    '#options' => array(
      'lock' => t('The user cannot rearrange nodes (locked)'),
    ),
    '#title' => t('Lock'),
    '#default_value' => $current['tabledrag_lock'],
  );
  $form['draggableviews_default_on_top'] = array(
    '#type' => 'radios',
    '#name' => 'draggableviews_default_on_top',
    '#title' => t('Behaviour of new nodes'),
    '#default_value' => $current['draggableviews_default_on_top'],
    '#description' => t('Nodes without a numerical order value assigned will be treated as new nodes. Decide where they should appear by default.'),
    '#options' => array(
      t('On Bottom'),
      t('On Top'),
    ),
  );
  $form['draggableviews_button_text'] = array(
    '#type' => 'textfield',
    '#size' => 20,
    '#title' => t('The label of the save button'),
    '#description' => t('Make the workflow more intuitive for the user.'),
    '#default_value' => $current['draggableviews_button_text'],
  );

  // Let extension modules alter the output
  foreach (module_implements('draggableviews_style_plugin_form_alter') as $module) {
    $function = $module . '_draggableviews_style_plugin_form_alter';
    $function($form, $form_state, $this);
  }
}