<?php

/**
 * @file
 * Install, update and uninstall functions for the group_core_comments module.
 */

use Drupal\user\Entity\Role;

/**
 * Implements hook_install().
 *
 * Perform actions related to the installation of group_core_comments.
 */
function group_core_comments_install() {
  // Grant the default permissions for this feature.
  user_role_grant_permissions(
    'sitemanager',
    [
      'delete all comments',
    ]
  );
}

/**
 * Enable 'delete all comments' permission for site manager users.
 */
function group_core_comments_update_8001(&$sandbox) {
  $roles = Role::loadMultiple();

  $permissions = [
    'delete all comments',
  ];

  /** @var \Drupal\user\Entity\Role $role */
  foreach ($roles as $role) {
    if ($role->id() === 'sitemanager') {
      user_role_grant_permissions($role->id(), $permissions);
    }
  }
}
