You are here

suggestion.install in Autocomplete Search Suggestions 3.0.x

Same filename and directory in other branches
  1. 8.2 suggestion.install
  2. 8 suggestion.install
  3. 7 suggestion.install

Contains suggestion.install.

File

suggestion.install
View source
<?php

/**
 * @file
 * Contains suggestion.install.
 */

/**
 * Implements hook_schema().
 */
function suggestion_schema() {
  $schema['suggestion'] = [
    'description' => 'Suggestion data.',
    'fields' => [
      'ngram' => [
        'description' => "The suggestion string.",
        'type' => 'varchar',
        'length' => 65,
        'binary' => TRUE,
        'not null' => TRUE,
      ],
      'src' => [
        'description' => "Suggestion source bitmap: 0 = disabled, 1 = content, 2 = surfer, 4 = priority",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ],
      'atoms' => [
        'description' => "The number of words in this suggestion.",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ],
      'qty' => [
        'description' => "The number of instances.",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ],
      'density' => [
        'description' => "The weighted average.",
        'type' => 'float',
        'unsigned' => TRUE,
        'precision' => 3,
        'not null' => TRUE,
        'default' => 1.0,
      ],
    ],
    'indexes' => [
      'atoms' => [
        'atoms',
      ],
      'density' => [
        'density',
      ],
      'qty' => [
        'qty',
      ],
      'ngram_atom' => [
        'atoms',
        'ngram',
      ],
      'ngram_atom_qty' => [
        'atoms',
        'ngram',
        'qty',
      ],
      'ngram_qty' => [
        'ngram',
        'qty',
      ],
    ],
    'primary key' => [
      'ngram',
    ],
  ];
  return $schema;
}

/**
 * Update migrate configuration settings to new architecture.
 */
function suggestion_update_8101() {
  $cfg = \Drupal::configFactory()
    ->getEditable('suggestion.config');
  $field_name = $cfg
    ->get('suggestion_field_name');
  $form_key = $cfg
    ->get('suggestion_form_id');
  $max = $cfg
    ->get('atoms');
  $cfg
    ->clear('atoms');
  $cfg
    ->clear('suggestion_field_name');
  $cfg
    ->clear('suggestion_form_id');
  $cfg
    ->save(TRUE);
  $cfg
    ->set('atoms_max', $max);
  $cfg
    ->set('atoms_min', 1);
  $cfg
    ->set('entry_style', 'simple');
  $cfg
    ->set('field_name', $field_name);
  $cfg
    ->set('form_key', $form_key);
  $cfg
    ->save(TRUE);
  drupal_flush_all_caches();
}

Functions

Namesort descending Description
suggestion_schema Implements hook_schema().
suggestion_update_8101 Update migrate configuration settings to new architecture.