-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontextual_aliases.install
52 lines (42 loc) · 1.55 KB
/
contextual_aliases.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
49
50
51
52
<?php
use Drupal\Core\Database\Database;
/**
* Implements hook_install().
*
* Alter the existing schema for `url_alias`. Add a `context` column and
* indices that include it.
*/
function contextual_aliases_install() {
$spec = array(
'description' => "The context for this alias..",
'type' => 'varchar_ascii',
'length' => 32,
'not null' => FALSE,
);
$schema = Database::getConnection()->schema();
$schema->addField('url_alias', 'context', $spec);
$table = \Drupal\Core\Path\AliasStorage::schemaDefinition();
$table['fields']['context'] = $spec;
$schema->dropIndex('url_alias', 'alias_langcode_pid');
$schema->dropIndex('url_alias', 'source_langcode_pid');
$schema->addIndex('url_alias', 'alias_context_langcode_pid', [
'alias', 'context', 'langcode', 'pid',
], $table);
$schema->addIndex('url_alias', 'source_context_langcode_pid', [
'source', 'context', 'langcode', 'pid',
], $table);
}
/**
* Implements hook_uninstall().
*
* Revert changes from `contextual_aliases_install`.
*/
function contextual_aliases_uninstall() {
$schema = Database::getConnection()->schema();
$schema->dropIndex('url_alias', 'alias_context_langcode_pid');
$schema->dropIndex('url_alias', 'source_context_langcode_pid');
$schema->dropField('url_alias', 'context');
$table = \Drupal\Core\Path\AliasStorage::schemaDefinition();
$schema->addIndex('url_alias', 'alias_langcode_pid', $table['indexes']['alias_langcode_pid'], $table);
$schema->addIndex('url_alias', 'source_langcode_pid', $table['indexes']['source_langcode_pid'], $table);
}