You are here

social_tagging.install in Open Social 8.8

Installation file for Social Tagging.

File

modules/social_features/social_tagging/social_tagging.install
View source
<?php

/**
 * @file
 * Installation file for Social Tagging.
 */
use Drupal\Core\Entity\EntityStorageException;

/**
 * Install the module.
 */
function social_tagging_install() {
  _social_tagging_assign_default_permissions();

  // Update field definitions.
  _social_tagging_field_definitions_update();

  // If the search module is enabled trigger updating of the indexes affected
  // by tagging.
  try {
    if (\Drupal::moduleHandler()
      ->moduleExists('social_search')) {
      social_search_resave_search_indexes([
        'social_content',
        'social_groups',
      ]);
    }
  } catch (EntityStorageException $e) {
    \Drupal::logger('social_tagging')
      ->info($e
      ->getMessage());
  }
}

/**
 * Assign the default permissions for this module.
 */
function _social_tagging_assign_default_permissions() {
  $permissions = [
    'administer social_tagging',
    'delete terms in social_tagging',
    'edit terms in social_tagging',
  ];

  // SM should be able to change the permissions.
  user_role_grant_permissions('sitemanager', $permissions);
}

/**
 * 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();
}

/**
 * Toggle group index.
 */
function social_tagging_update_8002() {

  // Update field definitions.
  _social_tagging_field_definitions_update();

  // Toggle the index groups.
  try {

    // If the search module is enabled we need to update the group index.
    if (\Drupal::moduleHandler()
      ->moduleExists('social_search')) {
      social_search_resave_search_indexes([
        'social_groups',
      ]);
    }
  } catch (EntityStorageException $e) {
    \Drupal::logger('social_tagging')
      ->info($e
      ->getMessage());
  }
}

/**
 * Update the field definitions on install, or in an update hook.
 */
function _social_tagging_field_definitions_update() {

  // Create field storage for the 'Highlight' base field.
  \Drupal::entityTypeManager()
    ->clearCachedDefinitions();
  \Drupal::service('entity.definition_update_manager')
    ->applyUpdates();
}

Functions

Namesort descending Description
social_tagging_install Install the module.
social_tagging_update_8001 Exclude landing pages from tagging.
social_tagging_update_8002 Toggle group index.
_social_tagging_assign_default_permissions Assign the default permissions for this module.
_social_tagging_field_definitions_update Update the field definitions on install, or in an update hook.