You are here

function content_field_instance_read in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 5 content_crud.inc \content_field_instance_read()
  2. 6.3 includes/content.crud.inc \content_field_instance_read()
  3. 6.2 includes/content.crud.inc \content_field_instance_read()

Load a field instance.

Parameters

$param: An array of properties to use in selecting a field instance. Valid keys:

  • 'type_name' - The name of the content type in which the instance exists.
  • 'field_name' - The name of the field whose instance is to be loaded.

if NULL, all instances will be returned.

Return value

The field arrays.

6 calls to content_field_instance_read()
content_field_instance_create in includes/content.crud.inc
Create a new field instance.
content_field_instance_delete in includes/content.crud.inc
Delete an existing field instance.
content_field_instance_update in includes/content.crud.inc
Update an existing field instance.
content_storage_type in ./content.module
Helper function for identifying the storage type for a field.
content_type_delete in includes/content.crud.inc
Make changes needed when a content type is deleted.

... See full list

File

includes/content.crud.inc, line 421
Create/Read/Update/Delete functions for CCK-defined object types.

Code

function content_field_instance_read($param = NULL) {
  if (is_array($param)) {

    // Turn the conditions into a query.
    foreach ($param as $key => $value) {
      $cond[] = 'nfi.' . db_escape_string($key) . " = '%s'";
      $args[] = $value;
    }
  }
  if (count($cond)) {
    $cond = " AND " . implode(' AND ', $cond);
  }
  $db_result = db_query("SELECT * FROM {" . content_instance_tablename() . "} nfi " . " JOIN {" . content_field_tablename() . "} nf ON nfi.field_name = nf.field_name " . " WHERE nf.active = 1 AND nfi.widget_active = 1 " . $cond . " ORDER BY nfi.weight ASC, nfi.label ASC", $args);
  $fields = array();
  while ($instance = db_fetch_array($db_result)) {

    // 'columns' is a reserved word in MySQL4, so our column is named 'db_columns'.
    $instance['columns'] = (array) (!empty($instance['db_columns']) ? unserialize($instance['db_columns']) : array());
    unset($instance['db_columns']);
    $instance['global_settings'] = (array) (!empty($instance['global_settings']) ? unserialize($instance['global_settings']) : array());
    foreach ($instance['global_settings'] as $key => $value) {
      $instance[$key] = $value;
    }
    unset($instance['global_settings']);
    if (!empty($instance['widget_settings'])) {
      $instance['widget_settings'] = (array) unserialize($instance['widget_settings']);
    }
    else {
      $instance['widget_settings'] = array();
    }
    if (!empty($instance['display_settings'])) {
      $instance['display_settings'] = (array) unserialize($instance['display_settings']);
    }
    else {
      $instance['display_settings'] = array();
    }
    $field = content_field_instance_expand($instance);

    // Invoke hook_content_fieldapi().
    module_invoke_all('content_fieldapi', 'read instance', $field);
    $fields[] = $field;
  }
  return $fields;
}