You are here

icon.install in Icon API 8

Same filename and directory in other branches
  1. 7 icon.install

icon.install Install, uninstall, and update functions for icon.module.

File

icon.install
View source
<?php

/**
 * @file
 * icon.install
 * Install, uninstall, and update functions for icon.module.
 */

/**
 * Implements hook_schema().
 */
function icon_schema() {
  $schema['icon_bundle'] = array(
    'description' => 'Stores the contents of icon bundles.',
    'fields' => array(
      'name' => array(
        'description' => 'The name of the icon bundle.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'bundle' => array(
        'description' => 'The array data belonging to the icon bundle.',
        'type' => 'blob',
        'serialize' => TRUE,
        'size' => 'big',
      ),
      'status' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
        'size' => 'tiny',
        'description' => 'The enabled status. (1 = enabled, 0 = disabled) of the icon bundle.',
      ),
    ),
    'primary key' => array(
      'name',
    ),
  );
  return $schema;
}

/**
 * Set module weight.
 */
function icon_set_module_weight($module, $weight = 100) {
  \Drupal::database()
    ->query("UPDATE {system} SET weight = :weight WHERE name = :module AND type = 'module'", array(
    ':module' => $module,
    ':weight' => $weight,
  ));
}

/**
 * Add fields to schema if they don't exist.
 */
function icon_install_create_fields($table, $fields) {
  static $schema;

  // Do not force schema refresh more than once per request.
  $schema = drupal_get_module_schema('icon', $table);
  foreach ($fields as $field) {
    if (!empty($schema['fields'][$field])) {
      if (!db_field_exists($table, $field)) {
        db_add_field($table, $field, $schema['fields'][$field]);
      }
      else {

        // The field exists, make sure field definition is up to date.
        db_change_field($table, $field, $field, $schema['fields'][$field]);
      }
    }
  }
}

Functions

Namesort descending Description
icon_install_create_fields Add fields to schema if they don't exist.
icon_schema Implements hook_schema().
icon_set_module_weight Set module weight.