From 0145c4c439c4cd00689d31bbdc4c5cc9a9279a29 Mon Sep 17 00:00:00 2001
From: Eric Alvares <erica@344430.no-reply.drupal.org>
Date: Sat, 26 Mar 2011 03:13:33 +0100
Subject: [PATCH] Issue #1104792 by Eric_A: Added chessboard_elements().

---
 chessboard.module |   73 ++++++++++++++++++++++++++++++++---------------------
 1 files changed, 44 insertions(+), 29 deletions(-)

diff --git a/chessboard.module b/chessboard.module
index e5436e5..fe15b2c 100644
--- a/chessboard.module
+++ b/chessboard.module
@@ -125,7 +125,9 @@ function chessboard_process_chessboard_notation($elements) {
   $params =& $matches[1];
 
   // Number of files: any integer (default: 8)
-  $elements['#file_max'] = preg_match('@[0-9]+@', $params, $m) ? $m[0] : 8;
+  if (preg_match('@[0-9]+@', $params, $m)) {
+    $elements['#file_max'] = $m[0];
+  }
 
   // Color of the upper left square: [l]ight (default), or [d]ark
   $elements['#square_color_first'] = (strpos($params, 'd') !== FALSE) ? 1 : 0;
@@ -193,6 +195,46 @@ function chessboard_process_chessboard_notation($elements) {
 }
 
 /**
+ * Implements hook_elements().
+ */
+function chessboard_elements() {
+  $types = array();
+  $types['chessboard_diagram'] = array(
+    '#attached' => array(
+      'css' => array(
+        drupal_get_path('module', 'chessboard') . '/chessboard.css' => array('media' => 'all', 'preprocess' => FALSE),
+      ),
+    ),
+    '#dimensions' => array(
+      'square' => array(
+        'width' => 40,
+        'height' => 40,
+      ),
+      'border-h' => array(
+        'width' => 40,
+        'height' => 4,
+      ),
+      'border-v' => array(
+        'width' => 4,
+        'height' => 40,
+      ),
+      'border-c' => array(
+        'width' => 4,
+        'height' => 4,
+      ),
+    ),
+    '#file_max' => 8,
+    '#image_directory_path' => drupal_get_path('module', 'chessboard') . '/default',
+    '#item' => NULL,
+    '#pre_render' => array('chessboard_process_chessboard_notation'),
+    '#prefix' => '<div class="chessboard">',
+    '#suffix' => '</div>',
+    '#theme' => 'chessboard',
+  );
+  return $types;
+}
+
+/**
  * Implements hook_theme().
  */
 function chessboard_theme() {
@@ -389,35 +431,8 @@ function _chessboard_filter_formatter_view($items) {
   $element = array();
   foreach ($items as $delta => $item) {
     $element[$delta] = array(
-      '#attached' => array(
-        'css' => array(
-          drupal_get_path('module', 'chessboard') . '/chessboard.css' => array('media' => 'all', 'preprocess' => FALSE),
-        ),
-      ),
-      '#dimensions' => array(
-        'square' => array(
-          'width' => 40,
-          'height' => 40,
-        ),
-        'border-h' => array(
-          'width' => 40,
-          'height' => 4,
-        ),
-        'border-v' => array(
-          'width' => 4,
-          'height' => 40,
-        ),
-        'border-c' => array(
-          'width' => 4,
-          'height' => 4,
-        ),
-      ),
-      '#pre_render' => array('chessboard_process_chessboard_notation'),
-      '#theme' => 'chessboard',
-      '#image_directory_path' => drupal_get_path('module', 'chessboard') . '/default',
       '#item' => $item,
-      '#prefix' => '<div class="chessboard">',
-      '#suffix' => '</div>',
+      '#type' => 'chessboard_diagram',
       '#weight' => $delta,
     );
   }
-- 
1.7.4

