function FieldInfo::getFieldById

Returns a field definition from a field ID.

This method only retrieves active fields, deleted or not.

Parameters

$field_id: The field ID.

Return value

The field definition, or NULL if no field was found.

File

modules/field/field.info.class.inc, line 306

Class

FieldInfo
Provides field and instance definitions for the current runtime environment.

Code

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;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.