You are here

social_group_flexible_group.install in Open Social 8.9

Install and update functions for the social_group_flexible_group module.

File

modules/social_features/social_group/modules/social_group_flexible_group/social_group_flexible_group.install
View source
<?php

/**
 * @file
 * Install and update functions for the social_group_flexible_group module.
 */
use Drupal\search_api\Entity\Index;

/**
 * Implements hook_install().
 */
function social_group_flexible_group_install() {

  // Set some default permissions.
  _social_group_flexible_group_set_permissions();

  // Set module weight higher as the weight of the "Social Group" module because
  // needs have the Views group type field which added via the "Social Group"
  // module.
  module_set_weight('social_group_flexible_group', 5);
}

/**
 * Function to set permissions.
 */
function _social_group_flexible_group_set_permissions() {
  $roles = \Drupal::entityQuery('user_role')
    ->condition('id', 'administrator', '<>')
    ->execute();
  foreach ($roles as $role) {
    $permissions = _social_group_flexible_group_get_permissions($role);
    user_role_grant_permissions($role, $permissions);
  }
}

/**
 * Build the permissions.
 *
 * @param string $role
 *   The role.
 *
 * @return array
 *   Returns an array containing the permissions.
 */
function _social_group_flexible_group_get_permissions($role) {

  // Anonymous.
  $permissions['anonymous'] = [];

  // Authenticated.
  $permissions['authenticated'] = array_merge($permissions['anonymous'], [
    'create flexible_group group',
  ]);

  // Content manager.
  $permissions['contentmanager'] = array_merge($permissions['authenticated'], []);

  // Site manager.
  $permissions['sitemanager'] = array_merge($permissions['contentmanager'], []);
  return $permissions[$role] ?? [];
}

/**
 * Implements hook_update_dependencies().
 */
function social_group_flexible_group_update_dependencies() {

  // New config changes should run after the features removal/revert.
  $dependencies['social_group_flexible_group'][8801] = [
    'social_core' => 8805,
  ];
  return $dependencies;
}

/**
 * Update view mode for new small teaser style.
 */
function social_group_flexible_group_update_8801() {

  /** @var \Drupal\update_helper\Updater $updateHelper */
  $updateHelper = \Drupal::service('update_helper.updater');

  // Execute configuration update definitions with logging of success.
  $updateHelper
    ->executeUpdate('social_group_flexible_group', 'social_group_flexible_group_update_8801');

  // Output logged messages to related channel of update execution.
  return $updateHelper
    ->logger()
    ->output();
}

/**
 * Trigger a search_api re-index.
 */
function social_group_flexible_group_update_8802() {
  $index = Index::load('social_groups');
  if ($index
    ->status()) {
    $index
      ->save();
    $index
      ->clear();
    $index
      ->reindex();
  }
}