You are here

social_tagging.install in Open Social 10.3.x

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;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;

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

/**
 * Install Tagging base field to profile entity type.
 */
function social_tagging_update_8003() {
  $field_storage_definition = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Tagging'))
    ->setDescription(t('Tagging field.'))
    ->setSetting('target_type', 'taxonomy_term')
    ->setSetting('handler', 'default:taxonomy_term')
    ->setSetting('handler_settings', [
    'target_bundles' => [
      'social_tagging' => 'social_tagging',
    ],
  ])
    ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
    ->setDisplayOptions('view', [
    'type' => 'hidden',
  ])
    ->setDisplayOptions('form', [
    'type' => 'options_select',
    'weight' => 3,
    'settings' => [],
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  \Drupal::entityDefinitionUpdateManager()
    ->installFieldStorageDefinition('social_tagging', 'profile', 'social_tagging', $field_storage_definition);
}

/**
 * Toggle user index.
 */
function social_tagging_update_8004() {

  // Update field definitions.
  _social_tagging_field_definitions_update();

  // Toggle the index users.
  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_users',
      ]);
    }
  } catch (EntityStorageException $e) {
    \Drupal::logger('social_tagging')
      ->info($e
      ->getMessage());
  }
}

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_update_8003 Install Tagging base field to profile entity type.
social_tagging_update_8004 Toggle user 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.