You are here

advpoll_field.install in Advanced Poll 7.3

Advanced Poll Field Install

Custom field widget used by Advanced Poll to link write-in flag to each available choice.

File

advpoll_field/advpoll_field.install
View source
<?php

/**
 * @file
 * Advanced Poll Field Install
 *
 * Custom field widget used by Advanced Poll to link write-in flag to each
 * available choice.
 */

/**
 * Implements hook_schema().
 *
 * Note: choice_id is necessary as a hidden field to provide a related unique
 * value for each choice field. Each time a choice is removed or reordered, its
 * delta is reset, as is the array provided in the node data.  As a result,
 * simply passing an index to the votingapi as the id for a given choice proved
 * inadequate in cases where choice delta changes due to content editing or
 * write-in values being merged.
 *
 * Initially I had planned to use an auto-incrementing primary key field but
 * this does not work with the custom field API, hence I settled for this
 * solution.  The unique value is just a randomized timestamp that has been
 * converted to hex for brevity.
 */
function advpoll_field_field_schema($field) {
  $columns = array(
    'choice_id' => array(
      'type' => 'varchar',
      'length' => 10,
      'not null' => TRUE,
    ),
    'choice' => array(
      'type' => 'varchar',
      'length' => 500,
      'not null' => TRUE,
    ),
    'write_in' => array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    ),
  );
  $indexes = array(
    'choice' => array(
      'choice',
    ),
  );
  return array(
    'columns' => $columns,
    'indexes' => $indexes,
  );
}

Functions

Namesort descending Description
advpoll_field_field_schema Implements hook_schema().