summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-09-11 03:42:34 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-09-11 03:42:34 +0000
commit3da4e0e0157b62d4aacd8857bd1f09c079718a05 (patch)
tree48ee50ed2dac4b49479dbe9d531fe021900f97f0
parent9b3c7eb44f6f0aa647a63380c2be8cd3a97f2571 (diff)
downloadbrdo-3da4e0e0157b62d4aacd8857bd1f09c079718a05.tar.gz
brdo-3da4e0e0157b62d4aacd8857bd1f09c079718a05.tar.bz2
#382464 by fgm and bjaspan: Disallow reserved field names.
-rw-r--r--modules/field/field.crud.inc9
-rw-r--r--modules/field/field.test14
2 files changed, 23 insertions, 0 deletions
diff --git a/modules/field/field.crud.inc b/modules/field/field.crud.inc
index 8e0ff1497..d837f8aaa 100644
--- a/modules/field/field.crud.inc
+++ b/modules/field/field.crud.inc
@@ -239,6 +239,15 @@ function field_create_field($field) {
throw new FieldException($message);
}
+ // Disallow reserved field names. This can't prevent all field name
+ // collisions with existing object properties, but some is better
+ // than none.
+ foreach (field_info_fieldable_types() as $type => $info) {
+ if (in_array($field['field_name'], $info['object keys'])) {
+ throw new FieldException(t('Attempt to create field name %name which is reserved by entity type %type.', array('%name' => $field['field_name'], '%type' => $type)));
+ }
+ }
+
$field += array(
'cardinality' => 1,
'translatable' => FALSE,
diff --git a/modules/field/field.test b/modules/field/field.test
index 04ceb0ab2..f99821f88 100644
--- a/modules/field/field.test
+++ b/modules/field/field.test
@@ -1543,6 +1543,20 @@ class FieldCrudTestCase extends FieldTestCase {
catch (FieldException $e) {
$this->pass(t('Cannot create a field with a name longer than 32 characters.'));
}
+
+ // Check that field name can not be an object key.
+ // "ftvid" is known as an object key from the "test_entity" type.
+ try {
+ $field_definition = array(
+ 'type' => 'test_field',
+ 'field_name' => 'ftvid',
+ );
+ $field = field_create_field($field_definition);
+ $this->fail(t('Cannot create a field bearing the name of an object key.'));
+ }
+ catch (FieldException $e) {
+ $this->pass(t('Cannot create a field bearing the name of an object key.'));
+ }
}
/**