forked from City-of-Helsinki/drupal-module-helfi-media-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helfi_media_map.install
40 lines (34 loc) · 1.19 KB
/
helfi_media_map.install
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
<?php
/**
* @file
* Install, uninstall and update hooks for helfi media map module.
*/
use Drupal\media\Entity\MediaType;
/**
* Implements hook_install().
*/
function helfi_media_map_install() {
if (MediaType::load('hel_map')) {
return;
}
/** @var \Drupal\media\MediaTypeInterface $media_type */
$media_type = MediaType::create([
'id' => 'hel_map',
'label' => 'Map (kartta.hel.fi, palvelukartta.hel.fi)',
'source' => 'hel_map',
]);
$media_type->save();
$source = $media_type->getSource();
$source_field = $source->createSourceField($media_type);
$source_configuration = $source->getConfiguration();
$source_configuration['source_field'] = $source_field->getName();
$source->setConfiguration($source_configuration);
$source_field->getFieldStorageDefinition()->save();
$source_field->save();
// Add the source field to the form display for the media type.
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
$form_display = \Drupal::service('entity_display.repository')->getFormDisplay('media', $media_type->id(), 'default');
$source->prepareFormDisplay($media_type, $form_display);
$form_display->save();
$media_type->save();
}