Skip to content
Snippets Groups Projects
Commit 3da4e0e0 authored by Angie Byron's avatar Angie Byron
Browse files

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

parent 9b3c7eb4
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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.'));
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment