function tablesort_example_install

Same name and namespace in other branches
  1. 7.x-1.x tablesort_example/tablesort_example.install \tablesort_example_install()
  2. 4.0.x modules/tablesort_example/tablesort_example.install \tablesort_example_install()

Implements hook_install().

Related topics

File

modules/tablesort_example/tablesort_example.install, line 16

Code

function tablesort_example_install() {
  // Let's fill the database with some values for sorting.
  $rows = [
    [
      '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',
    ],
  ];
  $db_connection = \Drupal::database();
  if ($db_connection->schema()
    ->tableExists('tablesort_example')) {
    foreach ($rows as $row) {
      $db_connection->insert('tablesort_example')
        ->fields($row)
        ->execute();
    }
  }
}