<?php

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

use Drupal\user\RoleInterface;

/**
 * PROCEED WITH CARE HERE!
 *
 * The below issue causes updates from the social_post module to be recognizes
 * as post updates from the social profile.
 *
 * Therefore don't create update hooks here!!!!
 *
 * https://www.drupal.org/node/2880361
 */

/**
 * Implements hook_install().
 *
 * Perform actions related to the installation of social_post.
 */
function social_post_install() {
  // Grant the default permissions for this feature.
  user_role_grant_permissions(
    RoleInterface::ANONYMOUS_ID,
    [
      'view public posts',
      'view published post entities',
    ]
  );
  user_role_grant_permissions(
    RoleInterface::AUTHENTICATED_ID,
    [
      'view public posts',
      'view published post entities',
    ]
  );
  user_role_grant_permissions(
    'verified',
    [
      'add post entities',
      'add post post entities',
      'delete own post entities',
      'edit own post entities',
      'view community posts',
      'view own unpublished post entities',
    ]
  );
  user_role_grant_permissions(
    'contentmanager',
    [
      'add post entities',
      'add post post entities',
      'delete own post entities',
      'edit own post entities',
      'view community posts',
      'view own unpublished post entities',
      'delete any post entities',
      'edit any post entities',
      'view unpublished post entities',
      'administer post entities',
    ]
  );
  user_role_grant_permissions(
    'sitemanager',
    [
      'add post entities',
      'add post post entities',
      'delete own post entities',
      'edit own post entities',
      'view community posts',
      'view own unpublished post entities',
      'delete any post entities',
      'edit any post entities',
      'view unpublished post entities',
      'administer post entities',
    ]
  );

  // Set the view mode for posts in activities.
  activity_creator_set_entity_view_mode('post', 'activity');
}

// IMPORTANT:
// @see: https://www.drupal.org/project/social/issues/3323713
// Don't add hook_update_N() implementations here!
// Add hook_update_N() for this module in social_core.install.
