scanner-8.x-1.0-rc3/scanner.install
scanner.install
<?php
/**
* @file
* Install, update and uninstall functions for the scanner module.
*/
use Drupal\Core\Url;
/**
* Implements hook_requirements().
*/
function scanner_requirements($phase): array {
$requirements = [];
if ($phase === 'runtime') {
// Get the current setting.
$word_boundary = \Drupal::config('scanner.admin_settings')->get('word_boundaries');
// Use the helper service to work out what the word boundaries option should
// be set to.
/** @var \Drupal\scanner\WordBoundariesHelper $word_boundaries_helper */
$word_boundaries_helper = \Drupal::service('scanner.word_boundaries_helper');
$should_be = $word_boundaries_helper->shouldBe();
if ($word_boundary === 'auto') {
$requirements['scanner_db'] = [
'severity' => REQUIREMENT_INFO,
'title' => 'Scanner',
'value' => t('The <a href="@url">"word boundaries" system</a> is set to "automatic" and will use the "@mode" mode.', [
'@url' => Url::fromRoute('scanner.admin_config')->toString(),
'@mode' => $should_be,
]),
];
}
elseif (!empty($word_boundary) && $word_boundary === $should_be) {
$requirements['scanner_db'] = [
'severity' => REQUIREMENT_INFO,
'title' => 'Scanner',
'value' => t('The <a href="@url">"word boundaries" setting</a> is correct.', [
'@url' => Url::fromRoute('scanner.admin_config')->toString(),
]),
];
}
else {
$requirements['scanner_db'] = [
'severity' => REQUIREMENT_WARNING,
'title' => 'Scanner',
'value' => t('Word boundaries setting is incorrect'),
'description' => t('Please update the <a href="@url">"word boundaries" setting</a>, it should be set to the "@mode" mode.', [
'@url' => Url::fromRoute('scanner.admin_config')->toString(),
'@mode' => $should_be,
]),
];
}
}
return $requirements;
}
/**
* Implements hook_schema().
*/
function scanner_schema(): array {
$schema['scanner'] = [
'description' => 'Holds info on recent replacements in case undo is needed.',
'fields' => [
'undo_id' => [
'description' => 'Row identifier',
'type' => 'serial',
'not null' => TRUE,
],
'undo_data' => [
'description' => 'What was changed',
'type' => 'text',
'size' => 'big',
'not null' => TRUE,
],
'undone' => [
'description' => 'Whether the replacement has been undone',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
],
'searched' => [
'description' => 'Text that was searched for',
'type' => 'varchar',
'length' => 256,
'not null' => TRUE,
],
'replaced' => [
'description' => 'Text that was used as replacement',
'type' => 'varchar',
'length' => 256,
'not null' => TRUE,
],
'count' => [
'description' => 'How many fields were modified on replacement',
'type' => 'int',
'not null' => TRUE,
],
'time' => [
'description' => 'How long the replacement took',
'type' => 'int',
'not null' => TRUE,
],
],
'primary key' => ['undo_id'],
];
return $schema;
}
