<?php
/**
 * @file
 * Installation file to manage TGF field settings.
 */

/**
 * Implements hook_update_N().
 * Implement field settings schema.
 */
function tgf_update_7100(&$sandbox) {
  drupal_install_schema('tgf');

  // Report a successful update.
  return t('Successfully performed update 7100: Implement field settings schema.');

  // Report a failure.
  throw new DrupalUpdateException('Update tgf-7100 failed.');
}

/**
 * Implements hook_update_N().
 * Add options to show or hide the title and limit counts.
 */
function tgf_update_7101(&$sandbox) {
  $fields = array(
    'display_title' => array(
      'description' => 'Show or hide the field title on the edit form.',
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    ),
    'display_counter' => array(
      'description' => 'Show or hide the cardinality counter on the edit form.',
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    ),
  );
  
  foreach ($fields as $fieldname => $field) {
    db_add_field('tgf_field_settings', $fieldname, $field);
  }
  
  // Provide a success messgage.
  return t('Update 7101 successful: Add options to show or hide the title and limit counts.');
  
  // If the update fails, provide a failure message.
  throw new DrupalUpdateException('Updated 7101 failed: Add options to show or hide the title and limit counts.');
}

/**
 * Implements hook_schema().
 */
function tgf_schema() {
  $schema['tgf_field_settings'] = array(
    'description' => 'Custom field settings to alter the Taxonomy Term Reference f',
    'fields' => array(
      'id' => array(
        'description' => 'The field instance id.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'parent_selectable' => array(
        'description' => 'Value for the Selectable Parent setting.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'display_title' => array(
        'description' => 'Show or hide the field title on the edit form.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'display_counter' => array(
        'description' => 'Show or hide the cardinality counter on the edit form.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('id'),
  );
  return $schema;
}