You are here

view_custom_table.install in Views Custom Table 8

Same filename and directory in other branches
  1. 7 view_custom_table.install
  2. 9.0.x view_custom_table.install

Installation functions for the View Custom Table module.

File

view_custom_table.install
View source
<?php

/**
 * @file
 * Installation functions for the View Custom Table module.
 */
use Drupal\Core\Database\Database;

/**
 * Add 'table_database' column so tables from other database can be implemented.
 */
function view_custom_table_update_8101() {
  $table_database = [
    'description' => 'Database of the table.',
    'type' => 'varchar',
    'length' => 100,
    'not null' => TRUE,
    'default' => 'default',
  ];
  $schema = Database::getConnection()
    ->schema();
  $schema
    ->addField('custom_table_view_data', 'table_database', $table_database);
}

/**
 * Take values from database and save to config file.
 */
function view_custom_table_update_8102() {
  $connection = Database::getConnection();
  $query = $connection
    ->select('custom_table_view_data')
    ->fields('custom_table_view_data');
  $result = $query
    ->execute()
    ->fetchAll();
  if (!empty($result)) {
    $config = \Drupal::service('config.factory')
      ->getEditable('view_custom_table.tables');
    foreach ($result as $row) {
      $config
        ->set($row->table_name . '.table_name', $row->table_name);
      $config
        ->set($row->table_name . '.table_database', $row->table_database);
      $config
        ->set($row->table_name . '.description', $row->description);
      $config
        ->set($row->table_name . '.column_relations', $row->column_relations);
      $config
        ->set($row->table_name . '.created_by', $row->created_by);
    }
    $config
      ->save();
  }
  Database::getConnection()
    ->schema()
    ->dropTable('custom_table_view_data');
}

Functions

Namesort descending Description
view_custom_table_update_8101 Add 'table_database' column so tables from other database can be implemented.
view_custom_table_update_8102 Take values from database and save to config file.