function token_install in Token 8
Same name and namespace in other branches
- 5 token.install \token_install()
- 6 token.install \token_install()
Implements hook_install().
File
- ./
token.install, line 42 - Install, update and uninstall functions for the token module.
Code
function token_install() {
// Create a token view mode for each entity type.
$info = \Drupal::entityTypeManager()
->getDefinitions();
foreach ($info as $entity_type => $entity_type_info) {
// We're only interested in entity types with a view builder.
if (!$entity_type_info
->getViewBuilderClass()) {
continue;
}
// Try to find a token view mode for that entity type.
$storage = \Drupal::entityTypeManager()
->getStorage('entity_view_mode');
// Add a token view mode if it does not already exist.
if (!$storage
->load("{$entity_type}.token")) {
$storage
->create([
'targetEntityType' => $entity_type,
'id' => "{$entity_type}.token",
'status' => TRUE,
'label' => t('Token'),
])
->save();
}
}
}