-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitteroauth.module
68 lines (62 loc) · 1.67 KB
/
twitteroauth.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
<?php
/**
* @file
* This module holds functions for twitteroauth.
*/
use Drupal\Core\Block\BlockPluginInterface;
/**
* Implements hook_theme().
*/
function twitteroauth_theme() {
return [
'twitteroauth_content' => [
'variables' => [
'display_text' => NULL,
'name' => NULL,
'tweet_link' => NULL,
'media_url' => NULL,
'screen_name' => NULL,
'created_at' => NULL,
'result_index' => NULL,
],
],
];
}
/**
* Implements hook_block_view_alter().
*/
function twitteroauth_block_view_alter(array &$build, BlockPluginInterface $block) {
if (strpos($block->getPluginId(), 'block_content') !== FALSE) {
$entity = \Drupal::service('entity.repository')->loadEntityByUuid('block_content', $block->getDerivativeId());
if (!empty($entity) && $entity->bundle() == 'twitteroauth_search') {
$build['#_entity'] = $entity;
$build['#pre_render'][] = '_twitteroauth_pre_render_fetchtweets';
}
}
}
/**
* Pre render callback to fetch twitter data.
*
* @param array $build
* The build.
*
* @return mixed
* The build.
*/
function _twitteroauth_pre_render_fetchtweets(array $build) {
if (!empty($build['#_entity'])) {
$build['content']['tweet_content'] = [
'#lazy_builder' => [
'twitteroauth.tweet_fetcher:fetch',
[
$build['#_entity']->field_twitteroauth_tweet_count->value,
trim($build['#_entity']->field_twitteroauth_search_query->value),
$build['#_entity']->field_twitteroauth_display_media->value,
$build['#_entity']->field_twitteroauth_expiration->value,
],
],
'#create_placeholder' => FALSE,
];
}
return $build;
}