simple_forum-8.x-1.0/simple_forum.module
simple_forum.module
<?php
/**
* @file
* This is the module to create simple forum.
*/
use Drupal\taxonomy\Entity\Term;
use Drupal\Core\Url;
/**
* Remove the setting while module uninstall.
* Implements hook_uninstall().
*/
function simple_forum_uninstall() {
\Drupal::configFactory()->getEditable('simple_forum.settings')->delete();
}
/**
* Add some terms to the simple forum vocabulary.
* Implements hook_install().
*/
function simple_forum_install() {
// Machine name of the Taxonomy vocabulary.
$vocab = 'simple_forum_';
// Term names to be added.
$items = [
'General',
];
foreach ($items as $item) {
$term = Term::create([
'parent' => [],
'name' => $item,
'vid' => $vocab,
])->save();
}
}
/**
* Implements hook_preprocess_page().
*/
function simple_forum_preprocess_page(array &$variables) : void {
// Module name: 'simple_forum', library name: 'simple_forum'.
$variables['#attached']['library'][] = 'simple_forum/simple_forum';
$variables['#attached']['drupalSettings']['simpleforum']['base_url'] = \Drupal::service('extension.list.module')->getPath('simple_forum');
$variables['#attached']['drupalSettings']['simpleforum']['site_url'] = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
$variables['#attached']['drupalSettings']['simpleforum']['module_url'] = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString().\Drupal::service('extension.list.module')->getPath('simple_forum');
}
/**
* Implements hook_preprocess_hook().
*/
function simple_forum_preprocess_comment__field_comments__simple_forum(&$variables) {
$variables['#cache']['max-age'] = 0;
$variables['currentuid'] = \Drupal::currentUser()->id();
}
/**
* Implements hook_theme_registry_alter().
*/
function simple_forum_theme_registry_alter(&$theme_registry) {
// Replace the path to the registered template so that Drupal looks for
// it in your module's templates folder.
$theme_registry['comment__field_comments__simple_forum']['path'] = \Drupal::service('extension.list.module')->getPath('simple_forum') . '/templates';
$theme_registry['comment__field_comments__simple_forum']['template'] = 'comments';
$theme_registry['comment__field_comments__simple_forum']['theme path'] = \Drupal::service('extension.list.module')->getPath('simple_forum') . '/templates';
}
