1 field.crud.inc | field_validate_instance($instance, $update = FALSE, $load_field = TRUE) |
Validates a field instance.
Parameters
$instance: The instance name to read.
$update: Whether this is a new or existing field instance.
$load_field: Whether the field instance should be read directly from config.
Related topics
File
- core/
modules/ field/ field.crud.inc, line 611 - Field CRUD API, handling field and field instance creation and deletion.
Code
function field_validate_instance($instance, $update = FALSE, $load_field = TRUE) {
$label = isset($instance['label']) ? $instance['label'] : $instance['field_name'];
// Check that the required properties exists.
if (empty($instance['entity_type'])) {
throw new FieldException(t('The field instance "@label" does not specify an entity type.', array('@label' => $label)));
}
if (empty($instance['bundle'])) {
throw new FieldException(t('The field instance "@label" does not specify a bundle type.', array('@label' => $label)));
}
if ($load_field) {
$field = field_read_field($instance['field_name']);
if (empty($field)) {
throw new FieldException(t('The field instance "@label" cannot be saved because the field "@name" does not exist.', array('@label' => $label, '@name' => $instance['field_name'])));
}
// Check that the field can be attached to this entity type.
if (!empty($field['entity_types']) && !in_array($instance['entity_type'], $field['entity_types'])) {
throw new FieldException(t('The field instance "@label" on the type "@entity_type" is not allowed.', array('@label' => $label, '@entity_type' => $instance['entity_type'])));
}
// @todo: Check that the widget type is known and can handle the field type.
// @todo: Check that the formatters are known and can handle the field type.
// @todo: Check that the display display modes are known for the entity type.
}
}