Skip to content

Commit f432f78

Browse files
authored
Merge pull request #63 from localgovdrupal/fix/1.x-61-update-hook
Add update hook to install the import entity and view
2 parents ca2adf1 + 5ec1b05 commit f432f78

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Localgov publications importer install and update hooks.
6+
*/
7+
8+
use Drupal\Core\Entity\ContentEntityType;
9+
use Drupal\localgov_publications_importer\Entity\Import;
10+
use Drupal\Core\Config\Config;
11+
use Drupal\Core\Config\FileStorage;
12+
13+
/**
14+
* Install entity definitions for the localgov_publications import entity.
15+
*/
16+
function localgov_publications_importer_update_10001(): void {
17+
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
18+
if (!$entity_definition_update_manager->getEntityType('import')) {
19+
$entity_type = new ContentEntityType([
20+
'id' => 'import',
21+
'class' => Import::class,
22+
'label' => t('import'),
23+
'base_table' => 'import',
24+
'entity_keys' => [
25+
'id' => 'id',
26+
'uuid' => 'uuid',
27+
],
28+
]);
29+
\Drupal::entityDefinitionUpdateManager()->installEntityType($entity_type);
30+
}
31+
}
32+
33+
/**
34+
* Install import admin view.
35+
*/
36+
function localgov_publications_importer_update_10002(): void {
37+
$path_to_module = \Drupal::service('extension.path.resolver')->getPath('module', 'localgov_publications_importer');
38+
$config_path = $path_to_module . '/config/install';
39+
$config_storage = new FileStorage($config_path);
40+
$view = \Drupal::service('config.factory')->getEditable('views.view.imports');
41+
assert($view instanceof Config);
42+
if ($view->isNew()) {
43+
$view->setData($config_storage->read('views.view.imports'));
44+
$view->save();
45+
}
46+
}

0 commit comments

Comments
 (0)