function robotstxt_install in RobotsTxt 8
Same name and namespace in other branches
- 5 robotstxt.install \robotstxt_install()
- 6 robotstxt.install \robotstxt_install()
- 7 robotstxt.install \robotstxt_install()
Implements hook_install().
File
- ./
robotstxt.install, line 13 - Install, update and uninstall functions for the robotstxt module.
Code
function robotstxt_install() {
$content = '';
// List of candidates for import.
$files = [
DRUPAL_ROOT . '/robots.txt',
DRUPAL_ROOT . '/sites/default/default.robots.txt',
drupal_get_path('module', 'robotstxt') . '/robots.txt',
];
foreach ($files as $file) {
if (file_exists($file) && is_readable($file)) {
$content = file_get_contents($file);
break;
}
}
\Drupal::configFactory()
->getEditable('robotstxt.settings')
->set('content', $content)
->save();
}