From d131266d351da2d741efffdddf8b10700ad921e2 Mon Sep 17 00:00:00 2001
From: tomogden <tomogden@441644.no-reply.drupal.org>
Date: Mon, 22 Dec 2014 16:20:42 -0500
Subject: [PATCH] Add field type definition.

---
 email.module    | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 email.theme.inc | 23 +++++++++++++++++++++++
 2 files changed, 72 insertions(+), 1 deletion(-)
 create mode 100644 email.theme.inc

diff --git a/email.module b/email.module
index a33d85c..0858cec 100644
--- a/email.module
+++ b/email.module
@@ -518,9 +518,57 @@ function email_admin_settings() {
 function email_content_migrate_instance_alter(&$instance_value, &$field_value) {
   if ($field_value['module'] == 'email') {
     foreach ($instance_value['display'] as $context => $settings) {
-      if (in_array($instance_value['display'][$context]['type'], array('default', 'plain', 'contact', 'spamspan'))) {
+      if (in_array(
+        $instance_value['display'][$context]['type'],
+        array('default', 'plain', 'contact', 'spamspan')
+      )) {
         $instance_value['display'][$context]['type'] = 'email_' . $instance_value['display'][$context]['type'];
       }
     }
   }
 }
+
+/**
+ * Implements hook_element_info().
+ */
+function email_element_info() {
+  $types = array();
+
+  $types['email'] = array(
+    '#input' => TRUE,
+    '#size' => 60,
+    '#maxlength' => 254,
+    '#autocomplete_path' => FALSE,
+    '#process' => array('ajax_process_form'),
+    '#element_validate' => array('email_validate_email'),
+    '#theme' => 'email',
+    '#theme_wrappers' => array('form_element'),
+  );
+
+  return $types;
+}
+
+/**
+ * Form element validation handler for #type 'email'.
+ */
+function email_validate_email(&$element, &$form_state) {
+  $value = trim($element['#value']);
+  form_set_value($element, $value, $form_state);
+
+  if ($value !== '' && !valid_email_address($value)) {
+    form_error($element, t('The email address %mail is not valid.', array('%mail' => $value)));
+  }
+}
+
+/**
+ * Implements hook_theme().
+ */
+function email_theme() {
+  return array(
+    'email' => array(
+      'arguments' => array('element' => NULL),
+      'render element' => 'element',
+      'file' => 'email.theme.inc',
+    ),
+  );
+}
diff --git a/email.theme.inc b/email.theme.inc
new file mode 100644
index 0000000..1e39a3c
--- /dev/null
+++ b/email.theme.inc
@@ -0,0 +1,23 @@
+<?php
+
+/**
+ * @file
+ * email theme functions.
+ */
+
+/**
+ * Returns HTML for an email field type.
+ */
+function theme_email($variables) {
+  $element = $variables['element'];
+  $element['#attributes']['type'] = 'email';
+  element_set_attributes(
+    $element,
+    array('id', 'name', 'value', 'size', 'maxlength', 'placeholder')
+  );
+  _form_set_class($element, array('form-text', 'form-email'));
+
+  $output = '<input' . drupal_attributes($element['#attributes']) . ' />';
+
+  return $output;
+}
--
2.2.1

