Returns a field definition from a field ID.
This method only retrieves active fields, deleted or not.
$field_id: The field ID.
The field definition, or NULL if no field was found.
public function getFieldById($field_id) {
// Read from the "static" cache.
if (isset($this->fieldsById[$field_id])) {
return $this->fieldsById[$field_id];
}
if (isset($this->unknownFields[$field_id])) {
return;
}
// No persistent cache, fields are only persistently cached as part of a
// bundle.
// Cache miss: read from definition.
if ($fields = field_read_fields(array(
'id' => $field_id,
), array(
'include_deleted' => TRUE,
))) {
$field = current($fields);
$field = $this
->prepareField($field);
// Store in the static cache.
$this->fieldsById[$field['id']] = $field;
if (!$field['deleted']) {
$this->fieldIdsByName[$field['field_name']] = $field['id'];
}
return $field;
}
else {
$this->unknownFields[$field_id] = TRUE;
}
}