Commit 157f6ee0 authored by Dries's avatar Dries
Browse files

- Patch #372330 by fgm: improved error messages to improve usability.

parent 1d2db443
...@@ -231,10 +231,12 @@ function field_create_field($field) { ...@@ -231,10 +231,12 @@ function field_create_field($field) {
// Ensure the field name is unique over active and disabled fields. // Ensure the field name is unique over active and disabled fields.
// We do not care about deleted 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)); $prior_field = field_read_field($field['field_name'], array('include_inactive' => TRUE));
if (!empty($prior_field)) { 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( $field += array(
...@@ -447,10 +449,12 @@ function field_create_instance($instance) { ...@@ -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. // Problem : this would mean that a UI module cannot update an instance with a disabled formatter.
// Ensure the field instance is unique. // 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)); $prior_instance = field_read_instance($instance['field_name'], $instance['bundle'], array('include_inactive' => TRUE));
if (!empty($prior_instance)) { 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); _field_write_instance($instance);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment