-
Notifications
You must be signed in to change notification settings - Fork 5
/
dgi_image_discovery.module
54 lines (46 loc) · 1.32 KB
/
dgi_image_discovery.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
<?php
/**
* @file
* General hook implementations.
*/
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\dgi_image_discovery\DIDImageItemList;
/**
* Implements hook_entity_base_field_info().
*/
function dgi_image_discovery_entity_base_field_info(EntityTypeInterface $entity_type) {
if ($entity_type->id() === 'node') {
$fields = [];
$fields['did_image'] = BaseFieldDefinition::create('did_image')
->setName('did_image')
->setLabel(t('DGI Image Discovery Discovered Image'))
->setDescription(t('Image to represent the given node.'))
->setComputed(TRUE)
->setClass(DIDImageItemList::class)
->setDisplayConfigurable('view', TRUE)
->setSetting('target_type', 'media');
return $fields;
}
}
/**
* Implements hook_field_formatter_info_alter().
*/
function dgi_image_discovery_field_formatter_info_alter(array &$info) {
$info['media_thumbnail']['field_types'][] = 'did_image';
}
/**
* Implements hook_views_data_alter().
*/
function dgi_image_discovery_views_data_alter(array &$data) {
$table = 'node';
if (isset($data[$table])) {
$data[$table]['did_image'] = [
'title' => t('DGI Image Discovery Discovered Image'),
'field' => [
'id' => 'did_image',
'field_name' => 'did_image',
],
];
}
}