social_tagging.install in Open Social 8.3
Same filename and directory in other branches
- 8.9 modules/social_features/social_tagging/social_tagging.install
- 8 modules/social_features/social_tagging/social_tagging.install
- 8.2 modules/social_features/social_tagging/social_tagging.install
- 8.4 modules/social_features/social_tagging/social_tagging.install
- 8.5 modules/social_features/social_tagging/social_tagging.install
- 8.6 modules/social_features/social_tagging/social_tagging.install
- 8.7 modules/social_features/social_tagging/social_tagging.install
- 8.8 modules/social_features/social_tagging/social_tagging.install
- 10.3.x modules/social_features/social_tagging/social_tagging.install
- 10.0.x modules/social_features/social_tagging/social_tagging.install
- 10.1.x modules/social_features/social_tagging/social_tagging.install
- 10.2.x modules/social_features/social_tagging/social_tagging.install
Installation file for Social Tagging.
File
modules/social_features/social_tagging/social_tagging.installView source
<?php
/**
* @file
* Installation file for Social Tagging.
*/
use Drupal\search_api\Entity\Index;
use Drupal\user\Entity\User;
/**
* Install the module.
*/
function social_tagging_install() {
_social_tagging_set_defaults();
/* @var Drupal\search_api\Entity\Index $index */
$index = Index::load('social_content');
\Drupal::logger('social_tagging')
->info('Loaded search index');
// If currently enabled we will first disabled and enable the index.
if ($index !== NULL && $index
->status()) {
\Drupal::logger('social_tagging')
->info('Search index exists');
// Elevate permissions so we can index *all* the items.
$accountSwitcher = Drupal::service('account_switcher');
$account = User::load(1);
$accountSwitcher
->switchTo($account);
// Disable and enable the index so the tagging field is properly added.
$index
->disable()
->save();
\Drupal::logger('social_tagging')
->info('Search index disabled');
$index
->enable()
->save();
\Drupal::logger('social_tagging')
->info('Search index enabled');
// Restore user account.
$accountSwitcher
->switchBack();
}
}
/**
* Exclude landing pages from tagging.
*/
function social_tagging_update_8001() {
// Set allow to true, since that's the case by default.
$config = \Drupal::getContainer()
->get('config.factory')
->getEditable('social_tagging.settings');
$config
->set('tag_node_type_landing_page', FALSE)
->save();
}
/**
* Function that sets the default configuration value(s) for this module.
*/
function _social_tagging_set_defaults() {
$permissions = [
'administer social_tagging',
'delete terms in social_tagging',
'edit terms in social_tagging',
];
// Set allow to true, since that's the case by default.
$config = \Drupal::getContainer()
->get('config.factory')
->getEditable('social_tagging.settings');
$config
->set('enable_content_tagging', 1)
->save();
$config
->set('allow_category_split', 1)
->save();
$config
->set('tag_node_type_landing_page', FALSE)
->save();
// SM should be able to change the permissions.
user_role_grant_permissions('sitemanager', $permissions);
}
Functions
Name![]() |
Description |
---|---|
social_tagging_install | Install the module. |
social_tagging_update_8001 | Exclude landing pages from tagging. |
_social_tagging_set_defaults | Function that sets the default configuration value(s) for this module. |