contest-8.x-1.0-alpha2/contest.install
contest.install
<?php /** * @file * Install, update, and uninstall functions for the Contest module. */ module_load_include('inc', 'contest', 'contest.install'); /** * Implements hook_install(). */ function contest_install() { _contest_install_date_format_install(); _contest_install_field_display(); drupal_flush_all_caches(); } /** * Implements hook_requirements(). */ function contest_requirements($phase) { $cfg = \Drupal::config('system.date'); $reqs = []; switch ($phase) { case 'install': if (!$cfg->get('country.default')) { $reqs['system'] = [ 'title' => t('Default Country'), 'value' => t("The default country isn't configured."), 'severity' => REQUIREMENT_ERROR, 'description' => t('Aborting! The default country needs to be configured. Please go to <a href="@url" target="_blank">regional settings</a> to configure.', ['@url' => \Drupal::url('system.regional_settings')]), ]; } if (!$cfg->get('timezone.default')) { $reqs['system'] = [ 'title' => t('Default Timezone'), 'value' => t("The default timezone isn't configured."), 'severity' => REQUIREMENT_ERROR, 'description' => t('Aborting! The default timezone needs to be configured. Please go to <a href="@url" target="_blank">regional settings</a> to configure.', ['@url' => \Drupal::url('system.regional_settings')]), ]; } break; } return $reqs; } /** * Implements hook_schema(). */ function contest_schema() { $schema['contest_entry'] = [ 'description' => 'Stores per-{users} entries for each {contest}.', 'fields' => [ 'cid' => [ 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'The {contest} entity this entry is for.', ], 'uid' => [ 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'description' => 'The {users}.uid this entry is from.', ], 'created' => [ 'type' => 'int', 'not null' => TRUE, 'default' => 0, 'description' => "The date the entry was created.", ], 'ip' => [ 'type' => 'varchar', 'length' => 15, 'not null' => TRUE, 'default' => '', 'description' => "A URL to the sponsors website.", ], 'winner' => [ 'type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'description' => "The number of winners.", ], ], 'foreign keys' => [ 'entry' => [ 'table' => 'contest_field_data', 'columns' => ['cid' => 'id'], ], 'contestant' => [ 'table' => 'users', 'columns' => ['uid' => 'uid'], ], ], 'indexes' => [ 'cid' => ['cid'], 'uid' => ['uid'], 'created' => ['created'], ], 'unique keys' => [ 'winners' => ['cid', 'uid', 'created', 'winner'], ], 'primary key' => ['cid', 'uid', 'created'], ]; return $schema; } /** * Implements hook_uninstall(). */ function contest_uninstall() { $fields = _contest_install_get_fields(); $mgr = \Drupal::entityManager()->getStorage('field_config'); // Delete the date format. _contest_install_date_format_delete(); // Delete the user fields. foreach (array_keys($fields) as $field_name) { $field = $mgr->load("user.user.$field_name"); if ($field) { $field->delete(); } } drupal_flush_all_caches(); }