-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreative.module
45 lines (38 loc) · 1.06 KB
/
creative.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* @file
* Contains hook implements for the creative module.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\creative\Service\Pattern;
/**
* Implements hook_entity_insert().
*/
function creative_entity_insert(EntityInterface $entity): void {
if ($entity->getEntityTypeId() == 'comment') {
/** @var \Drupal\creative\Service\Pattern $pattern */
$pattern = Drupal::getContainer()->get(Pattern::class);
$comment_subject = $entity->getSubject();
$comment_body = $entity->get('comment_body')->value;
if ($pattern->doesMatch($comment_subject)[0] || $pattern->doesMatch($comment_body)[0]) {
$entity->set('status', 0);
$entity->save();
}
}
}
/**
* Implements hook_theme().
*/
function creative_theme($existing, $type, $theme, $path): array {
return [
'creative_spam_comments' => [
'render-element' => 'children',
// Template == creative-spam-comments.html.twig.
'template' => 'creative-spam-comments',
'variables' => [
'items' => NULL,
'pager' => NULL,
],
],
];
}