You are here

public function FieldInfo::getField in Drupal 7

Returns a field definition from a field name.

This method only retrieves active, non-deleted fields.

Parameters

$field_name: The field name.

Return value

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

1 call to FieldInfo::getField()
FieldInfo::getInstances in modules/field/field.info.class.inc
Retrieves all active, non-deleted instances definitions.

File

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

Class

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

Code

public function getField($field_name) {

  // Read from the "static" cache.
  if (isset($this->fieldIdsByName[$field_name])) {
    $field_id = $this->fieldIdsByName[$field_name];
    return $this->fieldsById[$field_id];
  }
  if (isset($this->unknownFields[$field_name])) {
    return;
  }

  // Do not check the (large) persistent cache, but read the definition.
  // Cache miss: read from definition.
  if ($field = field_read_field($field_name)) {
    $field = $this
      ->prepareField($field);

    // Save in the "static" cache.
    $this->fieldsById[$field['id']] = $field;
    $this->fieldIdsByName[$field['field_name']] = $field['id'];
    return $field;
  }
  else {
    $this->unknownFields[$field_name] = TRUE;
  }
}