social_event_managers.install in Open Social 10.0.x
Same filename and directory in other branches
- 8.9 modules/social_features/social_event/modules/social_event_managers/social_event_managers.install
- 8 modules/social_features/social_event/modules/social_event_managers/social_event_managers.install
- 8.2 modules/social_features/social_event/modules/social_event_managers/social_event_managers.install
- 8.3 modules/social_features/social_event/modules/social_event_managers/social_event_managers.install
- 8.4 modules/social_features/social_event/modules/social_event_managers/social_event_managers.install
- 8.5 modules/social_features/social_event/modules/social_event_managers/social_event_managers.install
- 8.6 modules/social_features/social_event/modules/social_event_managers/social_event_managers.install
- 8.7 modules/social_features/social_event/modules/social_event_managers/social_event_managers.install
- 8.8 modules/social_features/social_event/modules/social_event_managers/social_event_managers.install
- 10.3.x modules/social_features/social_event/modules/social_event_managers/social_event_managers.install
- 10.1.x modules/social_features/social_event/modules/social_event_managers/social_event_managers.install
- 10.2.x modules/social_features/social_event/modules/social_event_managers/social_event_managers.install
Install, update and uninstall functions for the social_event_managers module.
File
modules/social_features/social_event/modules/social_event_managers/social_event_managers.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the social_event_managers module.
*/
use Drupal\user\Entity\Role;
use Symfony\Component\Yaml\Yaml;
/**
* Implements hook_install().
*
* Perform actions related to the installation of social_event_managers.
*/
function social_event_managers_install() {
// Fetch site manager role.
$role = Role::load('sitemanager');
// Set permission for site manager.
if ($role instanceof Role) {
// Set permission.
$role
->grantPermission('set social event managers settings');
$role
->trustData()
->save();
}
// Add enrollments permissions to CM and SM.
$roles = [
'sitemanager',
'contentmanager',
];
foreach ($roles as $rolename) {
$role = Role::load($rolename);
// Set permission for site manager.
if ($role instanceof Role) {
// Set permission.
$role
->grantPermission('manage everything enrollments');
$role
->trustData()
->save();
}
}
}
/**
* Perform actions related to the installation of social_event_managers.
*/
function social_event_managers_update_8001() {
social_event_managers_install();
}
/**
* Add manage enrollments permission to SM and CM.
*/
function social_event_managers_update_8003() {
$roles = [
'sitemanager',
'contentmanager',
];
foreach ($roles as $rolename) {
$role = Role::load($rolename);
// Set permission for site manager.
if ($role instanceof Role) {
// Set permission.
$role
->grantPermission('manage everything enrollments');
$role
->trustData()
->save();
}
}
}
/**
* Add new field for rendered profile entity so we can sort it.
*
* Load in a config file from an specific update hook that will never change.
* Update helper did not update all fields correctly.
*/
function social_event_managers_update_8004() {
$config_file = drupal_get_path('module', 'social_event_managers') . '/config/update/social_event_managers_update_8004.yml';
if (is_file($config_file)) {
$settings = Yaml::parse(file_get_contents($config_file));
if (is_array($settings)) {
$config = \Drupal::configFactory()
->getEditable('views.view.event_manage_enrollments');
$config
->setData($settings)
->save(TRUE);
}
}
}
/**
* Update labels for event organiser field.
*/
function social_event_managers_update_8005() {
// Load the existing configuration.
$config_name = 'field.field.node.event.field_event_managers';
$config = \Drupal::configFactory()
->getEditable($config_name);
$config_data = $config
->getRawData();
if (!empty($config_data['label'])) {
// This to ensure any custom added values are not affected.
if (strpos($config_data['label'], 'Event organisers') !== FALSE) {
$config_data['label'] = 'Organizers';
}
$config
->setData($config_data)
->save();
// Make sure we clear cached definitions for the fields.
\Drupal::service('entity_field.manager')
->clearCachedFieldDefinitions();
}
}
Functions
Name | Description |
---|---|
social_event_managers_install | Implements hook_install(). |
social_event_managers_update_8001 | Perform actions related to the installation of social_event_managers. |
social_event_managers_update_8003 | Add manage enrollments permission to SM and CM. |
social_event_managers_update_8004 | Add new field for rendered profile entity so we can sort it. |
social_event_managers_update_8005 | Update labels for event organiser field. |