You are here

social_event_type.install in Open Social 8.6

Install, update and uninstall functions for the social_event_type module.

File

modules/social_features/social_event/modules/social_event_type/social_event_type.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the social_event_type module.
 */
use Drupal\user\Entity\Role;

/**
 * Implements hook_install().
 *
 * Perform actions related to the installation of social_event_type.
 */
function social_event_type_install() {

  // Fetch sitemananger role.
  $role = Role::load('sitemanager');

  // Set permission for site manager.
  if ($role instanceof Role) {

    // Set permission.
    $role
      ->grantPermission('set social event type settings');
    $role
      ->grantPermission('edit terms in event_types');
    $role
      ->grantPermission('delete terms in event_types');
    $role
      ->trustData()
      ->save();

    // Set default event type settings.
    $config = \Drupal::configFactory()
      ->getEditable('social_event_type.settings');
    $config
      ->set('social_event_type_required', FALSE);
    $config
      ->set('social_event_type_select_changer', 5);
    $config
      ->save();
  }
}

/**
 * Implements hook_uninstall().
 *
 * Perform actions related to the de-installation of social_event_type.
 */
function social_event_type_uninstall() {

  // Fetch sitemananger role.
  $role = Role::load('sitemanager');

  // Set permission for site manager.
  if ($role instanceof Role) {

    // Set permission.
    $role
      ->revokePermission('set social event type settings');
    $role
      ->revokePermission('edit terms in event_types');
    $role
      ->revokePermission('delete terms in event_types');
    $role
      ->trustData()
      ->save();
  }

  // Also remove the fields and the vocabulary.
  \Drupal::configFactory()
    ->getEditable('field.field.node.event.field_event_type')
    ->delete();
  \Drupal::configFactory()
    ->getEditable('field.storage.node.field_event_type')
    ->delete();
  \Drupal::configFactory()
    ->getEditable('taxonomy.vocabulary.event_types')
    ->delete();
  \Drupal::configFactory()
    ->getEditable('social_event_type.settings')
    ->delete();
}

Functions