From 108987ae7e9a5a9a217b4c51de5e74cadd88b653 Mon Sep 17 00:00:00 2001
From: mamoun othman <artofeclipse@gmail.com>
Date: Thu, 1 Nov 2012 18:06:58 +0200
Subject: [PATCH] convert theme_taxonomy_overview_terms to twig.

---
 core/modules/taxonomy/taxonomy.module              |   95 ++++++++++++++++++++
 .../taxonomy/taxonomy-overview-terms.html.twig     |   15 +++
 2 files changed, 110 insertions(+), 0 deletions(-)
 create mode 100644 core/themes/stark/templates/taxonomy/taxonomy-overview-terms.html.twig

diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module
index a772e02..ad993c7 100644
--- a/core/modules/taxonomy/taxonomy.module
+++ b/core/modules/taxonomy/taxonomy.module
@@ -274,6 +274,7 @@ function taxonomy_theme() {
     ),
     'taxonomy_overview_terms' => array(
       'render element' => 'form',
+      'template' => 'taxonomy-overview-terms',
     ),
     'taxonomy_term' => array(
       'render element' => 'elements',
@@ -283,6 +284,100 @@ function taxonomy_theme() {
 }
 
 /**
+ * Default theme implementation to display a terms overview form as a sortable list of terms.
+ *
+ * $variables
+ *   An associative array containing:
+ *   - form: A render element representing the form.
+ *
+ * @see theme-taxonomy-overview-terms.html.twig
+ *
+ * @ingroup themeable
+ */
+function template_preprocess_taxonomy_overview_terms(&$variables) {
+  $form = $variables['form'];
+
+  $page_increment  = $form['#page_increment'];
+  $page_entries    = $form['#page_entries'];
+  $back_step     = $form['#back_step'];
+  $forward_step  = $form['#forward_step'];
+
+  // Add drag and drop if parent fields are present in the form.
+  if ($form['#parent_fields']) {
+    drupal_add_tabledrag('taxonomy', 'match', 'parent', 'term-parent', 'term-parent', 'term-id', FALSE);
+    drupal_add_tabledrag('taxonomy', 'depth', 'group', 'term-depth', NULL, NULL, FALSE);
+    drupal_add_js(drupal_get_path('module', 'taxonomy') . '/taxonomy.js');
+    drupal_add_js(array('taxonomy' => array('backStep' => $back_step, 'forwardStep' => $forward_step)), 'setting');
+    drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css');
+  }
+  drupal_add_tabledrag('taxonomy', 'order', 'sibling', 'term-weight');
+
+  $errors = form_get_errors() != FALSE ? form_get_errors() : array();
+  $rows = array();
+  foreach (element_children($form) as $key) {
+    if (isset($form[$key]['#term'])) {
+      $term = &$form[$key];
+
+      $row = array();
+      $row[] = (isset($term['#term']['depth']) && $term['#term']['depth'] > 0 ? theme('indentation', array('size' => $term['#term']['depth'])) : ''). drupal_render($term['view']);
+      if ($form['#parent_fields']) {
+        $term['tid']['#attributes']['class'] = array('term-id');
+        $term['parent']['#attributes']['class'] = array('term-parent');
+        $term['depth']['#attributes']['class'] = array('term-depth');
+        $row[0] .= drupal_render($term['parent']) . drupal_render($term['tid']) . drupal_render($term['depth']);
+      }
+      $term['weight']['#attributes']['class'] = array('term-weight');
+      $row[] = drupal_render($term['weight']);
+      $row[] = drupal_render($term['operations']);
+      $row = array('data' => $row);
+      $rows[$key] = $row;
+    }
+  }
+
+  // Add necessary classes to rows.
+  $row_position = 0;
+  foreach ($rows as $key => $row) {
+    $rows[$key]['class'] = array();
+    if (isset($form['#parent_fields'])) {
+      $rows[$key]['class'][] = 'draggable';
+    }
+
+    // Add classes that mark which terms belong to previous and next pages.
+    if ($row_position < $back_step || $row_position >= $page_entries - $forward_step) {
+      $rows[$key]['class'][] = 'taxonomy-term-preview';
+    }
+
+    if ($row_position !== 0 && $row_position !== count($rows) - 1) {
+      if ($row_position == $back_step - 1 || $row_position == $page_entries - $forward_step - 1) {
+        $rows[$key]['class'][] = 'taxonomy-term-divider-top';
+      }
+      elseif ($row_position == $back_step || $row_position == $page_entries - $forward_step) {
+        $rows[$key]['class'][] = 'taxonomy-term-divider-bottom';
+      }
+    }
+
+    // Add an error class if this row contains a form error.
+    foreach ($errors as $error_key => $error) {
+      if (strpos($error_key, $key) === 0) {
+        $rows[$key]['class'][] = 'error';
+      }
+    }
+    $row_position++;
+  }
+
+  if (empty($rows)) {
+    $rows[] = array(array('data' => $form['#empty_text'], 'colspan' => '3'));
+  }
+
+  $header = array(t('Name'), t('Weight'), t('Operations'));
+  $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'taxonomy')));
+  $output .= drupal_render_children($form);
+  $output .= theme('pager');
+
+  $variables['content'] = $output;
+}
+
+/**
  * Implements hook_menu().
  */
 function taxonomy_menu() {
diff --git a/core/themes/stark/templates/taxonomy/taxonomy-overview-terms.html.twig b/core/themes/stark/templates/taxonomy/taxonomy-overview-terms.html.twig
new file mode 100644
index 0000000..0862b3e
--- /dev/null
+++ b/core/themes/stark/templates/taxonomy/taxonomy-overview-terms.html.twig
@@ -0,0 +1,15 @@
+{#
+/**
+* @file
+* Default theme implementation to display a terms overview form as a sortable list of terms.
+*
+* Available variables:
+* - content: taxonomy terms overview form as a sortable list of terms.
+*
+* @see template_preprocess
+* @see template_preprocess_taxonomy_overview_terms
+*
+* @ingroup themeable
+*/
+#}
+{{ content }}
\ No newline at end of file
-- 
1.7.5.4

