examples-3.x-dev/modules/tablesort_example/tablesort_example.install

modules/tablesort_example/tablesort_example.install
<?php

/**
 * @file
 * Install and uninstall functions for the tablesort_example module.
 *
 * This file contains the functions required to perform install and
 * uninstall operations.
 */

/**
 * Implements hook_install().
 *
 * @ingroup tablesort_example
 */
function tablesort_example_install() {
  // Let's fill the database with some values for sorting.
  // The values in the following array are used by
  // Drupal\Tests\tablesort_example\Functional\TableSortExampleTest::testTableSortExampleBasic()
  // to verify the functionality of the sortable table. If the values used in
  // this array are changed, the test code must be changed too.
  $rows = [
    // cspell:disable
    ['numbers' => 1, 'alpha' => 'e', 'random' => '912cv21'],
    ['numbers' => 2, 'alpha' => 'a', 'random' => '0kuykuh'],
    ['numbers' => 3, 'alpha' => 'm', 'random' => 'fuye8734h'],
    ['numbers' => 4, 'alpha' => 'w', 'random' => '80jsv772'],
    ['numbers' => 5, 'alpha' => 'o', 'random' => 'd82sf-csj'],
    ['numbers' => 6, 'alpha' => 's', 'random' => 'au832'],
    ['numbers' => 7, 'alpha' => 'e', 'random' => 't982hkv'],
    // cspell:enable
  ];

  $db_connection = \Drupal::database();
  if ($db_connection->schema()->tableExists('tablesort_example')) {
    foreach ($rows as $row) {
      $db_connection->insert('tablesort_example')->fields($row)->execute();
    }
  }
}

/**
 * Implements hook_uninstall().
 *
 * It's good to clean up after ourselves.
 *
 * @ingroup tablesort_example
 */
function tablesort_example_uninstall() {
  $db_connection = \Drupal::database();
  $db_connection->schema()->dropTable('tablesort_example');
}

/**
 * Implements hook_schema().
 *
 * @ingroup tablesort_example
 */
function tablesort_example_schema() {
  $schema['tablesort_example'] = [
    'description' => 'Stores some values for sorting fun.',
    'fields' => [
      'numbers' => [
        'description' => 'This column simply holds numbers values',
        'type' => 'varchar',
        'length' => 2,
        'not null' => TRUE,
      ],
      'alpha' => [
        'description' => 'This column simply holds alpha values',
        'type' => 'varchar',
        'length' => 2,
        'not null' => TRUE,
      ],
      'random' => [
        'description' => 'This column simply holds random values',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
      ],
    ],
    'primary key' => ['numbers'],
  ];

  return $schema;
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc