#382464 by fgm and bjaspan: Disallow reserved field names.
parent
9b3c7eb44f
commit
3da4e0e015
|
@ -239,6 +239,15 @@ function field_create_field($field) {
|
||||||
throw new FieldException($message);
|
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(
|
$field += array(
|
||||||
'cardinality' => 1,
|
'cardinality' => 1,
|
||||||
'translatable' => FALSE,
|
'translatable' => FALSE,
|
||||||
|
|
|
@ -1543,6 +1543,20 @@ class FieldCrudTestCase extends FieldTestCase {
|
||||||
catch (FieldException $e) {
|
catch (FieldException $e) {
|
||||||
$this->pass(t('Cannot create a field with a name longer than 32 characters.'));
|
$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.'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue