-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomain_unique_path_alias.install
48 lines (45 loc) · 1.55 KB
/
domain_unique_path_alias.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
41
42
43
44
45
46
47
48
<?php
/**
* @file
* Install, update, and uninstall functions for domain_unique_path_alias.
*
* @ingroup domain_unique_path_alias
*/
/**
* Implements hook_install().
*
* Add domain ids to existing aliases.
*/
function domain_unique_path_alias_install($is_syncing) {
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
$entity_type_manager = \Drupal::entityTypeManager();
/** @var \Drupal\domain_unique_path_alias\DomainUniquePathAliasHelper $path_alias_helper */
$path_alias_helper = \Drupal::service('domain_unique_path_alias.helper');
$path_alias_storage = $entity_type_manager->getStorage('path_alias');
$aliases = $path_alias_storage->getQuery()
->notExists('domain_id')
->accessCheck(FALSE)
->execute();
foreach ($aliases as $alias) {
$path_alias = $path_alias_storage->load($alias);
$path = $path_alias->getPath();
$domain_id = $path_alias_helper->getPathDomainId($path);
if (!empty($domain_id)) {
$path_alias->set('domain_id', $domain_id);
$path_alias->save();
}
}
}
/**
* Implements hook_uninstall().
*
* Core does not properly purge field provided by configuration entities.
* There are a few related issues and @todo notices in core to this effect.
* Instead, we handle field purges ourselves.
*/
function domain_unique_path_alias_uninstall() {
// Do a pass of purging on deleted Field API data, if any exists.
$limit = \Drupal::config('field.settings')->get('purge_batch_size');
field_purge_batch($limit);
\Drupal::entityTypeManager()->clearCachedDefinitions();
}