-
Notifications
You must be signed in to change notification settings - Fork 2
/
linkback.module
76 lines (61 loc) · 2.02 KB
/
linkback.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* @file
* Contains linkback.module..
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Queue\QueueFactory;
use Drupal\Core\Queue\QueueInterface;
use Symfony\Component\DomCrawler\Crawler;
use Drupal\Core\Routing\RouteMatchInterface;
// User-agent used when extracting titles and excerpts.
define('LINKBACK_UA', 'Drupal Linkback (+http://drupal.org/project/linkback)');
// The local node could not be found.
define('LINKBACK_ERROR_LOCAL_NODE_NOT_FOUND', 1);
// The local node could not be used as a linkback resource (e.g., linkbacks are
// disabled on the node).
define('LINKBACK_ERROR_LOCAL_NODE_REFBACK_NOT_ALLOWED', 2);
// The linkback has previously been registered.
define('LINKBACK_ERROR_REFBACK_ALREADY_REGISTERED', 3);
// The linkback source does not contain the link to target.
define('LINKBACK_ERROR_REMOTE_URL_MISSING_LINK', 4);
/**
* Implements hook_help().
* @param string $route_name
*/
function linkback_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the linkback module.
case 'help.page.linkback':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('linkback raw functionality') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_ENTITY_TYPE_insert().
*/
function linkback_entity_insert(EntityInterface $entity) {
// TODO allow other entities to use linkbacks.
if ($entity->getEntityTypeId() != 'node') {
return;
}
if (!(bool) $entity->get('status')) {
return;
}
/** @var QueueFactory $queue_factory */
$queue_factory = \Drupal::service('queue');
/** @var QueueInterface $queue */
$queue = $queue_factory->get(\Drupal::config('linkback.settings')->get('use_cron') ? 'cron_linkback_sender' : 'manual_linkback_sender');
$item = new \stdClass();
$item->nid = $entity->id();
$queue->createItem($entity);
}
/**
* Implements hook_ENTITY_TYPE_update().
*/
function linkback_entity_update(EntityInterface $entity) {
linkback_entity_insert($entity);
}