You are here

function template_preprocess_faq_draggable_question_order_table in Frequently Asked Questions 8

Theme function for question ordering drag and drop table.

File

./faq.module, line 118
The FAQ module allows users to create a FAQ page, with questions and answers displayed in different styles, according to the settings.

Code

function template_preprocess_faq_draggable_question_order_table(&$variables) {
  $form = $variables['form'];
  $options = array(
    'table_id' => 'question-sort',
    'action' => 'order',
    'relationship' => 'sibling',
    'group' => 'sort',
  );
  $header = array(
    '',
    t('Question'),
    '',
    t('Sort'),
  );
  $rows = array();
  foreach (Element::children($form) as $key) {

    // Add class to group weight fields for drag and drop.
    $form[$key]['sort']['#attributes']['class'] = array(
      'sort',
    );
    $form[$key]['nid']['#attributes']['class'] = array(
      'hidden-nid',
    );
    $row = array(
      '',
    );
    $row[] = \Drupal::service('renderer')
      ->render($form[$key]['title']);
    $row[] = \Drupal::service('renderer')
      ->render($form[$key]['nid']);
    $row[] = \Drupal::service('renderer')
      ->render($form[$key]['sort']);
    $rows[] = array(
      'data' => $row,
      'class' => array(
        'draggable',
      ),
    );
  }
  $table = array(
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#attributes' => array(
      'id' => 'question-sort',
    ),
  );
  drupal_attach_tabledrag($table, $options);
  $variables['order_table'] = $table;
}