You are here

document.install in Document 7

Same filename and directory in other branches
  1. 6 document.install
  2. 8.x document.install

File

document.install
View source
<?php

require_once drupal_get_path('module', 'document') . '/document.inc';
function document_install() {

  // use get_t() to get the name of our localization function for translation
  // during install, when t() is not available.
  $t = get_t();

  //Create a vocabulary for documents.
  document_get_vocid();

  // Ensure the node type is available.
  node_types_rebuild();
  $types = node_type_get_types();
  node_add_body_field($types['document'], 'Abstract');
  $vocab = document_get_vocab();

  //Create document type field.
  $field = array(
    'field_name' => 'document_types',
    'type' => 'taxonomy_term_reference',
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => $vocab->machine_name,
          'parent' => 0,
        ),
      ),
    ),
  );
  field_create_field($field);
  $instance = array(
    'field_name' => 'document_types',
    'entity_type' => 'node',
    'label' => $t('Document type(s)'),
    'bundle' => 'document',
    'required' => true,
    'widget' => array(
      'type' => 'options_select',
    ),
    'display' => array(
      'default' => array(
        'type' => 'hidden',
      ),
      'teaser' => array(
        'type' => 'hidden',
      ),
    ),
  );
  field_create_instance($instance);
}
function document_uninstall() {
  variable_del('document_path');
  variable_del('document_allow_external');
  variable_del('document_allow_websearch');
  variable_del('document_publish_email');
  variable_del('document_publish_subject');
  variable_del('document_publish_body');
  variable_del('document_path');
  variable_del('document_vocabulary');
  $instance = field_info_instance('node', 'document_types', 'document');
  field_delete_instance($instance, TRUE);
  node_type_delete('document');
}

/**
 * Implementation of hook_schema().
 */
function document_schema() {
  $schema['document'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'fid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'type' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'length' => 1024,
      ),
      'author' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'length' => 255,
      ),
      'publish_year' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'size' => 'normal',
      ),
      'keywords' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'length' => 1024,
      ),
      'url' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'length' => 1024,
      ),
      'external' => array(
        'type' => 'int',
        'not null' => TRUE,
        'size' => 'normal',
      ),
    ),
    'primary key' => array(
      'vid',
    ),
  );
  return $schema;
}

Functions