-
Notifications
You must be signed in to change notification settings - Fork 6
/
minimal_share.module
80 lines (69 loc) · 2.12 KB
/
minimal_share.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
77
78
79
80
<?php
/**
* @file
* Contains minimal_share.module.
*/
use \Drupal\Core\Entity\EntityInterface;
use \Drupal\Core\Entity\Display\EntityViewDisplayInterface;
/**
* Implements hook_theme().
*/
function minimal_share_theme() {
return [
'minimal_share' => [
'variables' => [
'providers' => NULL,
],
],
'minimal_share_item' => [
'variables' => [
'title' => NULL,
'attributes' => NULL,
],
],
];
}
/**
* Implements hook_entity_extra_field_info().
*/
function minimal_share_entity_extra_field_info() {
$extra = [];
/** @var \Drupal\minimal_share\MinimalShareManager $manager */
$manager = \Drupal::service('minimal_share.manager');
$config = $manager->getConfig();
// Iterate all enabled entity types and provide
// an extra field for each bundle.
foreach ($config['entity_types'] as $entity_type) {
/** @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface $definition */
$bundle_info = \Drupal::service('entity_type.bundle.info');
$bundles = $bundle_info->getBundleInfo($entity_type);
foreach ($bundles as $bundle => $info) {
$extra[$entity_type][$bundle]['display']['minimal_share'] = [
'label' => t('Minimal Share'),
'description' => t('Minimal share buttons'),
'visible' => FALSE,
];
}
}
return $extra;
}
/**
* Implements hook_entity_view().
*/
function minimal_share_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
/** @var \Drupal\minimal_share\MinimalShareManager $manager */
$manager = \Drupal::service('minimal_share.manager');
$entity_type = $entity->getEntityTypeId();
// Make sure entity type has been enabled and component has been added
// on "Manage display" page.
if ($manager->entityTypeEnabled($entity_type) && $display->getComponent('minimal_share')) {
$share_info = $manager->buildShareInfo($entity);
$build['minimal_share'] = $manager->build($share_info);
}
}
/**
* Implements template_preprocess_HOOK().
*/
function template_preprocess_minimal_share_item(&$variables) {
$variables['label'] = $variables['title'];
}