From 95821e3fa91a46ff2fb6775f7ed4a4681bd31132 Mon Sep 17 00:00:00 2001
From: Dave Reid <dave@davereid.net>
Date: Tue, 31 May 2011 21:32:40 -0500
Subject: [PATCH] Issue #1174634: Added the HTML5 tel form element.

---
 includes/form.inc                           |   46 ++++++++++++++++++++++++--
 modules/simpletest/drupal_web_test_case.php |    1 +
 modules/system/system.module                |    9 +++++
 3 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/includes/form.inc b/includes/form.inc
index c0e2ec7..f10a0e4 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -3635,8 +3635,48 @@ function theme_textfield($variables) {
   element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength'));
   _form_set_class($element, array('form-text'));
 
+  $extra = form_add_autocomplete($element);
+  $output = '<input' . drupal_attributes($element['#attributes']) . ' />';
+
+  return $output . $extra;
+}
+
+/**
+ * Returns HTML for an tel form element.
+ *
+ * @param $variables
+ *   An associative array containing:
+ *   - element: An associative array containing the properties of the element.
+ *     Properties used: #title, #value, #description, #size, #maxlength,
+ *     #placeholder, #required, #attributes, #autocomplete_path.
+ *
+ * @ingroup themeable
+ */
+function theme_tel($variables) {
+  $element = $variables['element'];
+  element_set_attributes($element, array('type', 'id', 'name', 'value', 'size', 'maxlength', 'placeholder'));
+  _form_set_class($element, array('form-text', 'form-tel'));
+
+  $extra = form_add_autocomplete($element);
+  $output = '<input' . drupal_attributes($element['#attributes']) . ' />';
+
+  return $output . $extra;
+}
+
+/**
+ * Return the autocompletion HTML for a form element.
+ *
+ * @param $element
+ *   The renderable element to process for autocompletion.
+ *
+ * @return
+ *   The rendered autocompletion element HTML, or an empty string if the field
+ *   has no autocompletion enabled.
+ */
+function form_add_autocomplete(&$element) {
   $extra = '';
-  if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) {
+
+  if (!empty($element['#autocomplete_path']) && drupal_valid_path($element['#autocomplete_path'])) {
     drupal_add_library('system', 'drupal.autocomplete');
     $element['#attributes']['class'][] = 'form-autocomplete';
 
@@ -3649,9 +3689,7 @@ function theme_textfield($variables) {
     $extra = '<input' . drupal_attributes($attributes) . ' />';
   }
 
-  $output = '<input' . drupal_attributes($element['#attributes']) . ' />';
-
-  return $output . $extra;
+  return $extra;
 }
 
 /**
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index b60c682..d71b2d7 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -2144,6 +2144,7 @@ class DrupalWebTestCase extends DrupalTestCase {
           case 'textarea':
           case 'hidden':
           case 'password':
+          case 'tel':
             $post[$name] = $edit[$name];
             unset($edit[$name]);
             break;
diff --git a/modules/system/system.module b/modules/system/system.module
index 3ebc657..9dc5203 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -355,6 +355,15 @@ function system_element_info() {
     '#theme' => 'textfield',
     '#theme_wrappers' => array('form_element'),
   );
+  $types['tel'] = array(
+    '#input' => TRUE,
+    '#size' => 60,
+    '#maxlength' => 128,
+    '#autocomplete_path' => FALSE,
+    '#process' => array('ajax_process_form'),
+    '#theme' => 'tel',
+    '#theme_wrappers' => array('form_element'),
+  );
   $types['machine_name'] = array(
     '#input' => TRUE,
     '#default_value' => NULL,
-- 
1.7.3.1

