From 157f6ee03005153cfd43f4952acf512734381968 Mon Sep 17 00:00:00 2001
From: Dries Buytaert <dries@buytaert.net>
Date: Mon, 7 Sep 2009 15:50:52 +0000
Subject: [PATCH] - Patch #372330 by fgm: improved error messages to improve
 usability.

---
 modules/field/field.crud.inc | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/modules/field/field.crud.inc b/modules/field/field.crud.inc
index cae2ecdf5360..2ce0998ce6fa 100644
--- a/modules/field/field.crud.inc
+++ b/modules/field/field.crud.inc
@@ -231,10 +231,12 @@ function field_create_field($field) {
 
   // Ensure the field name is unique over active and disabled fields.
   // We do not care about deleted fields.
-  // TODO : do we want specific messages when clashing with a disabled or inactive field ?
   $prior_field = field_read_field($field['field_name'], array('include_inactive' => TRUE));
   if (!empty($prior_field)) {
-    throw new FieldException(t('Attempt to create field name %name which already exists.', array('%name' => $field['field_name'])));
+    $message = $prior_field['active']?
+      t('Attempt to create field name %name which already exists and is active.', array('%name' => $field['field_name'])):
+      t('Attempt to create field name %name which already exists, although it is inactive.', array('%name' => $field['field_name']));
+    throw new FieldException($message);
   }
 
   $field += array(
@@ -447,10 +449,12 @@ function field_create_instance($instance) {
   // Problem : this would mean that a UI module cannot update an instance with a disabled formatter.
 
   // Ensure the field instance is unique.
-  // TODO : do we want specific messages when clashing with a disabled or inactive instance ?
   $prior_instance = field_read_instance($instance['field_name'], $instance['bundle'], array('include_inactive' => TRUE));
   if (!empty($prior_instance)) {
-    throw new FieldException(t('Attempt to create a field instance %field_name,%bundle which already exists.', array('%field_name' => $instance['field_name'], '%bundle' => $instance['bundle'])));
+    $message = $prior_instance['widget']['active']?
+      t('Attempt to create a field instance %field_name,%bundle which already exists and is active.', array('%field_name' => $instance['field_name'], '%bundle' => $instance['bundle'])):
+      t('Attempt to create a field instance %field_name,%bundle which already exists, although inactive.', array('%field_name' => $instance['field_name'], '%bundle' => $instance['bundle']));
+    throw new FieldException($message);
   }
 
   _field_write_instance($instance);
-- 
GitLab