Commit 3da4e0e0 authored by webchick's avatar webchick

#382464 by fgm and bjaspan: Disallow reserved field names.

parent 9b3c7eb4
......@@ -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,
......
......@@ -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.'));
}
}
/**
......
Markdown is supported
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