home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (text.install)

This example Drupal source code file (text.install) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, columns, false, format, function, not, null, php, table, text, type, value, varchar

The text.install Drupal example source code

<?php
// $Id: text.install,v 1.4 2010/10/20 15:57:42 webchick Exp $

/**
 * @file
 * Install, update and uninstall functions for the text module.
 */

/**
 * Implements hook_field_schema().
 */
function text_field_schema($field) {
  switch ($field['type']) {
    case 'text':
      $columns = array(
        'value' => array(
          'type' => 'varchar',
          'length' => $field['settings']['max_length'],
          'not null' => FALSE,
        ),
      );
      break;

    case 'text_long':
      $columns = array(
        'value' => array(
          'type' => 'text',
          'size' => 'big',
          'not null' => FALSE,
        ),
      );
      break;

    case 'text_with_summary':
      $columns = array(
        'value' => array(
          'type' => 'text',
          'size' => 'big',
          'not null' => FALSE,
        ),
        'summary' => array(
          'type' => 'text',
          'size' => 'big',
          'not null' => FALSE,
        ),
      );
      break;
  }
  $columns += array(
    'format' => array(
      'type' => 'varchar',
      'length' => 255,
      'not null' => FALSE,
    ),
  );
  return array(
    'columns' => $columns,
    'indexes' => array(
      'format' => array('format'),
    ),
    'foreign keys' => array(
      'format' => array(
        'table' => 'filter_format',
        'columns' => array('format' => 'format'),
      ),
    ),
  );
}

/**
 * Implements hook_update_dependencies().
 */
function text_update_dependencies() {
  // Ensure that format columns are only changed after Filter module has changed
  // the primary records.
  $dependencies['text'][7000] = array(
    'filter' => 7010,
  );

  return $dependencies;
}

/**
 * Change text field 'format' columns into varchar.
 */
function text_update_7000() {
  $spec = array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => FALSE,
  );
  $fields = _update_7000_field_read_fields(array(
    'module' => 'text',
    'storage_type' => 'field_sql_storage',
  ));
  foreach ($fields as $field_name => $field) {
    if ($field['deleted']) {
      $table = "field_deleted_data_{$field['id']}";
      $revision_table = "field_deleted_revision_{$field['id']}";
    }
    else {
      $table = "field_data_{$field['field_name']}";
      $revision_table = "field_revision_{$field['field_name']}";
    }
    $column = $field['field_name'] . '_' . 'format';
    db_change_field($table, $column, $column, $spec);
    db_change_field($revision_table, $column, $column, $spec);
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal text.install source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.