filter.install 4.37 KB
Newer Older
1 2
<?php

3 4
/**
 * @file
5
 * Install, update, and uninstall functions for the Filter module.
6 7
 */

8
/**
9
 * Implements hook_schema().
10 11
 */
function filter_schema() {
12
  $schema['filter'] = array(
13
    'description' => 'Table that maps filters (HTML corrector) to text formats (Filtered HTML).',
14
    'fields' => array(
15
      'format' => array(
16 17
        'type' => 'varchar',
        'length' => 255,
18
        'not null' => TRUE,
19
        'description' => 'Foreign key: The {filter_format}.format to which this filter is assigned.',
20 21 22 23 24 25
      ),
      'module' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
26
        'description' => 'The origin module of the filter.',
27
      ),
28 29 30
      'name' => array(
        'type' => 'varchar',
        'length' => 32,
31
        'not null' => TRUE,
32 33
        'default' => '',
        'description' => 'Name of the filter being referenced.',
34 35 36 37 38
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
39
        'description' => 'Weight of filter within format.',
40 41 42 43 44 45 46 47
      ),
      'status' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Filter enabled status. (1 = enabled, 0 = disabled)',
      ),
      'settings' => array(
48
        'type' => 'blob',
49 50 51 52 53
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
        'description' => 'A serialized array of name value pairs that store the filter settings for the specific format.',
      ),
54
    ),
55
    'primary key' => array('format', 'name'),
56
    'indexes' => array(
57
      'list' => array('weight', 'module', 'name'),
58
    ),
59
  );
60
  $schema['filter_format'] = array(
61
    'description' => 'Stores text formats: custom groupings of filters, such as Filtered HTML.',
62
    'fields' => array(
63
      'format' => array(
64 65
        'type' => 'varchar',
        'length' => 255,
66
        'not null' => TRUE,
67
        'description' => 'Primary Key: Unique machine name of the format.',
68 69 70 71 72 73
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
74
        'description' => 'Name of the text format (Filtered HTML).',
75
        'translatable' => TRUE,
76 77 78 79 80 81
      ),
      'cache' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
82
        'description' => 'Flag to indicate whether format is cacheable. (1 = cacheable, 0 = not cacheable)',
83
      ),
84 85 86 87 88 89 90 91
      'status' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
        'size' => 'tiny',
        'description' => 'The status of the text format. (1 = enabled, 0 = disabled)',
      ),
92 93 94 95
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
96
        'description' => 'Weight of text format to use when listing.',
97
      ),
98 99
    ),
    'primary key' => array('format'),
100 101 102
    'unique keys' => array(
      'name' => array('name'),
    ),
103
    'indexes' => array(
104
      'status_weight' => array('status', 'weight'),
105
    ),
106 107 108
  );

  $schema['cache_filter'] = drupal_get_schema_unprocessed('system', 'cache');
109
  $schema['cache_filter']['description'] = 'Cache table for the Filter module to store already filtered pieces of text, identified by text format and hash of the text.';
110 111 112 113

  return $schema;
}

114 115 116 117 118 119 120 121 122
/**
 * Implements hook_install().
 */
function filter_install() {
  // All sites require at least one text format (the fallback format) that all
  // users have access to, so add it here. We initialize it as a simple, safe
  // plain text format with very basic formatting, but it can be modified by
  // installation profiles to have other properties.
  $plain_text_format = array(
123
    'format' => 'plain_text',
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    'name' => 'Plain text',
    'weight' => 10,
    'filters' => array(
      // Escape all HTML.
      'filter_html_escape' => array(
        'weight' => 0,
        'status' => 1,
      ),
      // URL filter.
      'filter_url' => array(
        'weight' => 1,
        'status' => 1,
      ),
      // Line break filter.
      'filter_autop' => array(
        'weight' => 2,
        'status' => 1,
      ),
    ),
  );
  $plain_text_format = (object) $plain_text_format;
  filter_format_save($plain_text_format);

  // Set the fallback format to plain text.
  variable_set('filter_fallback_format', $plain_text_format->format);
}