-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter_api.module
More file actions
49 lines (43 loc) · 1.09 KB
/
Copy pathtwitter_api.module
File metadata and controls
49 lines (43 loc) · 1.09 KB
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
<?php
/**
* @file
*/
/**
* Implements hook_entity_operation_alter().
*/
use Drupal\twitter_api\Controller\TwitterController;
use Drupal\Core\Url;
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_entity_operation_alter().
*
* Add 'Post to Twitter' button to book_quote operations.
*/
function twitter_api_entity_operation_alter(array &$operations, EntityInterface $entity) {
$entityTypeId = $entity->getEntityTypeId();
if ($entityTypeId !== 'node') {
return;
}
$nodeType = $entity->getType();
$nodeId = $entity->id();
if ($nodeType === 'book_quote') {
// Add custom operation.
$editUrl = Url::fromRoute('twitter_api.operation.post', ['node_id' => $nodeId]);
$operations['post_to_twitter'] = [
'title' => t('Post to Twitter'),
'weight' => 20,
'url' => $editUrl,
];
}
}
/**
* Implements hook_cron().
*/
function twitter_api_cron() {
$controller = new TwitterController(
Drupal::service('entity.manager'),
Drupal::service('file_system'),
Drupal::service('logger.factory')->get('action')
);
$controller->postNext();
}