You are here

function ttext_field in Internationalization 5

Implementation of hook_field().

File

experimental/ttext.module, line 33
Defines simple ttext field types.

Code

function ttext_field($op, &$node, $field, &$node_field, $teaser, $page) {
  $fieldname = $field['field_name'];

  //drupal_set_message("DEBUG: ttext_field $op, name = $fieldname");
  switch ($op) {
    case 'validate':
      return text_field($op, $node, $field, $node_field, $teaser, $page);
    case 'update':
      foreach ($node_field as $delta => $item) {
        db_query("DELETE FROM {node_data_field_ttext} WHERE nid = %d AND vid = %d AND name = '%s' AND language = '%s' AND delta = %d", $node->nid, $node->vid, $fieldname, i18n_get_lang(), $delta);
      }

    //db_query("UPDATE {node_data_field_ttext} SET value = '%s' WHERE nid = %d AND vid = %d AND name = '%s' AND language = '%s' AND delta = %d", $value, $node->nid, $node->vid, $fieldname, i18n_get_lang(), $delta);

    // Intentional no break
    case 'insert':
      foreach ($node_field as $delta => $item) {
        db_query("INSERT INTO {node_data_field_ttext}(nid, vid, name, language, delta, value) VALUES(%d, %d, '%s', '%s', %d, '%s')", $node->nid, $node->vid, $fieldname, i18n_get_lang(), $delta, $item['value']);
      }
      break;
    case 'load':
      $result = db_query("SELECT delta, value FROM {node_data_field_ttext} WHERE nid = %d AND vid = %d AND name = '%s' AND language = '%s' AND delta = %d", $node->nid, $node->vid, $fieldname, i18n_get_lang());
      while ($data = db_fetch_object($result)) {
        $node_field[$data->delta]['value'] = $data->value;
      }
      return array(
        $fieldname => $node_field,
      );
    case 'delete':
      break;
  }
}