thunder_liveblog.install in Thunder 6.2.x
Same filename and directory in other branches
- 8.5 modules/thunder_liveblog/thunder_liveblog.install
- 8.2 modules/thunder_liveblog/thunder_liveblog.install
- 8.3 modules/thunder_liveblog/thunder_liveblog.install
- 8.4 modules/thunder_liveblog/thunder_liveblog.install
- 6.0.x modules/thunder_liveblog/thunder_liveblog.install
- 6.1.x modules/thunder_liveblog/thunder_liveblog.install
The install file.
File
modules/thunder_liveblog/thunder_liveblog.installView source
<?php
/**
* @file
* The install file.
*/
use Drupal\field\Entity\FieldConfig;
use Drupal\user\Entity\Role;
/**
* Implements hook_install().
*
* Configures form and view display of the field_embed_media.
*/
function thunder_liveblog_install() {
// Add permissions to thunder users.
$liveblog_permissions = [
'add liveblog_post entity',
'create liveblog content',
'delete any liveblog content',
'delete liveblog revisions',
'delete liveblog_post entity',
'delete own liveblog content',
'edit any liveblog content',
'edit liveblog_post entity',
'edit own liveblog content',
'revert liveblog revisions',
'view liveblog revisions',
];
foreach ([
'editor',
'seo',
] as $role) {
if ($role = Role::load($role)) {
foreach ($liveblog_permissions as $permission) {
$role
->grantPermission($permission);
}
$role
->save();
}
}
}
/**
* Delete liveblog provided config, we have our own.
*/
function thunder_liveblog_module_preinstall($module) {
if ('thunder_liveblog' == $module) {
$entity_query = \Drupal::entityQuery('node');
$results = $entity_query
->condition('type', 'liveblog')
->exists('body')
->count()
->execute();
if (($field = FieldConfig::load('node.liveblog.body')) && !$results) {
$field
->delete();
field_purge_batch(10);
}
$configs = [
'core.entity_form_display.node.liveblog.default',
'core.entity_form_display.liveblog_post.liveblog_post.default',
'core.entity_view_display.liveblog_post.liveblog_post.default',
'core.entity_view_display.node.liveblog.default',
];
$configFactory = \Drupal::configFactory();
foreach ($configs as $config) {
$configFactory
->getEditable($config)
->delete();
}
}
}
Functions
Name | Description |
---|---|
thunder_liveblog_install | Implements hook_install(). |
thunder_liveblog_module_preinstall | Delete liveblog provided config, we have our own. |