social_post_photo.install in Open Social 8.8
Same filename and directory in other branches
- 8.9 modules/social_features/social_post/modules/social_post_photo/social_post_photo.install
- 8 modules/social_features/social_post/modules/social_post_photo/social_post_photo.install
- 8.2 modules/social_features/social_post/modules/social_post_photo/social_post_photo.install
- 8.3 modules/social_features/social_post/modules/social_post_photo/social_post_photo.install
- 8.4 modules/social_features/social_post/modules/social_post_photo/social_post_photo.install
- 8.5 modules/social_features/social_post/modules/social_post_photo/social_post_photo.install
- 8.6 modules/social_features/social_post/modules/social_post_photo/social_post_photo.install
- 8.7 modules/social_features/social_post/modules/social_post_photo/social_post_photo.install
- 10.3.x modules/social_features/social_post/modules/social_post_photo/social_post_photo.install
- 10.0.x modules/social_features/social_post/modules/social_post_photo/social_post_photo.install
- 10.1.x modules/social_features/social_post/modules/social_post_photo/social_post_photo.install
- 10.2.x modules/social_features/social_post/modules/social_post_photo/social_post_photo.install
The Social post photo installation.
File
modules/social_features/social_post/modules/social_post_photo/social_post_photo.installView source
<?php
/**
* @file
* The Social post photo installation.
*/
use Drupal\user\RoleInterface;
/**
* Install hook for Social Post Photo.
*/
function social_post_photo_install() {
// Set some default permissions.
_social_post_photo_set_permissions();
// Change post to photo.
_social_post_photo_settype('post', 'photo');
}
/**
* Function to set permissions.
*/
function _social_post_photo_set_permissions() {
$roles = \Drupal::entityQuery('user_role')
->condition('id', 'administrator', '<>')
->execute();
foreach ($roles as $role) {
$permissions = _social_post_photo_get_permissions($role);
user_role_grant_permissions($role, $permissions);
}
}
/**
* Return the permissions per role.
*
* @param string $role
* The role to get the permissions for.
*
* @return array
* A list of permissions.
*/
function _social_post_photo_get_permissions($role) {
// Anonymous.
$permissions[RoleInterface::ANONYMOUS_ID] = [];
// Authenticated.
$permissions[RoleInterface::AUTHENTICATED_ID] = array_merge($permissions[RoleInterface::ANONYMOUS_ID], [
'add photo post entities',
]);
// Content manager.
$permissions['contentmanager'] = array_merge($permissions[RoleInterface::AUTHENTICATED_ID], []);
// Site manager.
$permissions['sitemanager'] = array_merge($permissions['contentmanager'], []);
return $permissions[$role] ?? [];
}
/**
* Uninstall hook for Social Post Photo.
*/
function social_post_photo_uninstall() {
// Change photo to post.
_social_post_photo_settype('photo', 'post');
$configs = [
'core.entity_form_display.post.photo.default',
'core.entity_form_display.post.photo.group',
'core.entity_form_display.post.photo.profile',
'core.entity_view_display.post.photo.activity',
'core.entity_view_display.post.photo.activity_comment',
'core.entity_view_display.post.photo.default',
'field.field.post.photo.field_post',
'field.field.post.photo.field_post_comments',
'field.field.post.photo.field_post_image',
'field.field.post.photo.field_recipient_group',
'field.field.post.photo.field_recipient_user',
'field.field.post.photo.field_visibility',
'field.storage.post.field_post_image',
'image.style.social_post_photo',
'social_post.post_type.photo',
];
foreach ($configs as $config) {
// Deleting config.
\Drupal::configFactory()
->getEditable($config)
->delete();
}
}
/**
* Set the number of comments on Post Teaser and Full display.
*/
function social_post_photo_update_8001() {
\Drupal::service('config.installer')
->installDefaultConfig('module', 'social_post_photo');
}
Functions
Name | Description |
---|---|
social_post_photo_install | Install hook for Social Post Photo. |
social_post_photo_uninstall | Uninstall hook for Social Post Photo. |
social_post_photo_update_8001 | Set the number of comments on Post Teaser and Full display. |
_social_post_photo_get_permissions | Return the permissions per role. |
_social_post_photo_set_permissions | Function to set permissions. |