You are here

function content_field_instance_read in Content Construction Kit (CCK) 6.2

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 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.

$include_inactive: TRUE will return field instances that are 'inactive', because their field module or widget module is currently disabled.

Return value

The field arrays.

11 calls to content_field_instance_read()
ContentCrudBasicTest::testBasic in tests/content.crud.test
content_field_basic_form_submit in includes/content.admin.inc
Create a new field for a content type.
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.

... See full list

File

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

Code

function content_field_instance_read($param = NULL, $include_inactive = FALSE) {
  $cond = array();
  $args = array();
  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 (!$include_inactive) {
    $cond[] = 'nf.active = 1';
    $cond[] = 'nfi.widget_active = 1';
  }
  $where = $cond ? ' WHERE ' . 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} ORDER BY nfi.weight ASC, nfi.label ASC", $args);
  $fields = array();
  while ($instance = db_fetch_array($db_result)) {

    // Unserialize arrays.
    foreach (array(
      'widget_settings',
      'display_settings',
      'global_settings',
      'db_columns',
    ) as $key) {
      $instance[$key] = !empty($instance[$key]) ? (array) unserialize($instance[$key]) : array();
    }

    // 'columns' is a reserved word in MySQL4, so our column is named 'db_columns'.
    $instance['columns'] = $instance['db_columns'];
    unset($instance['db_columns']);

    // Unfold 'global_settings'.
    foreach ($instance['global_settings'] as $key => $value) {
      $instance[$key] = $value;
    }
    unset($instance['global_settings']);

    // Put the field in the $field => 'widget' structure that is used
    // all around content.module.
    $field = content_field_instance_expand($instance);

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