From a50e06b30109ac9e56399d8e668c14a94795f048 Mon Sep 17 00:00:00 2001 From: Harlor Date: Thu, 1 Apr 2021 12:47:25 +0200 Subject: [PATCH] #2880361 Move social_post update hooks --- .../social_post_updates.info.yml | 7 + .../social_post_updates.install | 126 ++++++++++++++++++ .../social_post/social_post.install | 104 --------------- 3 files changed, 133 insertions(+), 104 deletions(-) create mode 100644 modules/social_features/social_post/modules/social_post_updates/social_post_updates.info.yml create mode 100644 modules/social_features/social_post/modules/social_post_updates/social_post_updates.install diff --git a/modules/social_features/social_post/modules/social_post_updates/social_post_updates.info.yml b/modules/social_features/social_post/modules/social_post_updates/social_post_updates.info.yml new file mode 100644 index 00000000000..baf8869fbe1 --- /dev/null +++ b/modules/social_features/social_post/modules/social_post_updates/social_post_updates.info.yml @@ -0,0 +1,7 @@ +name: 'Social Post Updates' +description: 'Provides updates for social_post.' +type: module +core: 8.x +dependencies: + - social:social_post +package: Social diff --git a/modules/social_features/social_post/modules/social_post_updates/social_post_updates.install b/modules/social_features/social_post/modules/social_post_updates/social_post_updates.install new file mode 100644 index 00000000000..11a23101125 --- /dev/null +++ b/modules/social_features/social_post/modules/social_post_updates/social_post_updates.install @@ -0,0 +1,126 @@ + 8802, + ]; + + return $dependencies; +} + +/** + * Set the view mode to use when shown in activities. + */ +function social_post_updates_update_8801() { + activity_creator_set_entity_view_mode('post', 'activity'); +} + +/** + * Give access to creating posts of specific types. + */ +function social_post_updates_update_8802(&$sandbox) { + if (!isset($sandbox['total'])) { + $sandbox['total'] = \Drupal::entityQuery('user_role') + ->condition('id', 'administrator', '<>') + ->count() + ->execute(); + + $sandbox['processed'] = 0; + $sandbox['limit'] = Settings::get('entity_update_batch_size', 50); + $sandbox['permissions'] = array_keys(\Drupal::service('social_post.permission_generator')->permissions()); + } + + $role_ids = \Drupal::entityQuery('user_role') + ->condition('id', 'administrator', '<>') + ->range($sandbox['processed'], $sandbox['limit']) + ->execute(); + + $storage = \Drupal::entityTypeManager()->getStorage('user_role'); + + foreach ($role_ids as $role_id) { + /** @var \Drupal\user\RoleInterface $role */ + $role = $storage->load($role_id); + + if ($role->hasPermission('add post entities')) { + user_role_grant_permissions($role_id, $sandbox['permissions']); + } + } + + $sandbox['processed'] += count($role_ids); + + $sandbox['#finished'] = $sandbox['processed'] / $sandbox['total']; +} + +/** + * Create "Featured" view mode/display for post. + */ +function social_post_updates_update_8804() { + // Create a new post featured entity view mode. + if (!EntityViewMode::load('post.featured')) { + EntityViewMode::create([ + 'targetEntityType' => 'post', + 'id' => 'post.featured', + 'status' => TRUE, + 'label' => t('Featured'), + ])->save(); + } + + // Create view display for post bundle of Post entity. + if (!EntityViewDisplay::load('post.post.featured')) { + $display = EntityViewDisplay::load('post.post.default')->toArray(); + unset( + $display['content']['field_post_comments'], + $display['hidden']['like_and_dislike'] + ); + $display['content']['like_and_dislike'] = [ + 'weight' => 3, + 'region' => 'content', + ]; + $display = array_merge($display, [ + 'uuid' => NULL, + '_core' => NULL, + 'targetEntityType' => 'post', + 'mode' => 'featured', + ]); + EntityViewDisplay::create($display)->save(); + } +} + +/** + * Update likes in post activity and comment view modes. + */ +function social_post_updates_update_8901() { + /** @var \Drupal\update_helper\Updater $updateHelper */ + $updateHelper = \Drupal::service('update_helper.updater'); + + // Execute configuration update definitions with logging of success. + $updateHelper->executeUpdate('social_post', 'social_post_updates_update_8901'); + + // Output logged messages to related channel of update execution. + return $updateHelper->logger()->output(); +} diff --git a/modules/social_features/social_post/social_post.install b/modules/social_features/social_post/social_post.install index 988ccab9bd1..e40fab5afab 100644 --- a/modules/social_features/social_post/social_post.install +++ b/modules/social_features/social_post/social_post.install @@ -93,107 +93,3 @@ function _social_post_get_permissions($role) { } return []; } - -/** - * Implements hook_update_dependencies(). - */ -function social_post_update_dependencies() { - // Run the activities view mode update after the final features removal ran. - $dependencies['social_post'][8801] = [ - 'social_core' => 8802, - ]; - - return $dependencies; -} - -/** - * Set the view mode to use when shown in activities. - */ -function social_post_update_8801() { - activity_creator_set_entity_view_mode('post', 'activity'); -} - -/** - * Give access to creating posts of specific types. - */ -function social_post_update_8802(&$sandbox) { - if (!isset($sandbox['total'])) { - $sandbox['total'] = \Drupal::entityQuery('user_role') - ->condition('id', 'administrator', '<>') - ->count() - ->execute(); - - $sandbox['processed'] = 0; - $sandbox['limit'] = Settings::get('entity_update_batch_size', 50); - $sandbox['permissions'] = array_keys(\Drupal::service('social_post.permission_generator')->permissions()); - } - - $role_ids = \Drupal::entityQuery('user_role') - ->condition('id', 'administrator', '<>') - ->range($sandbox['processed'], $sandbox['limit']) - ->execute(); - - $storage = \Drupal::entityTypeManager()->getStorage('user_role'); - - foreach ($role_ids as $role_id) { - /** @var \Drupal\user\RoleInterface $role */ - $role = $storage->load($role_id); - - if ($role->hasPermission('add post entities')) { - user_role_grant_permissions($role_id, $sandbox['permissions']); - } - } - - $sandbox['processed'] += count($role_ids); - - $sandbox['#finished'] = $sandbox['processed'] / $sandbox['total']; -} - -/** - * Create "Featured" view mode/display for post. - */ -function social_post_update_8804() { - // Create a new post featured entity view mode. - if (!EntityViewMode::load('post.featured')) { - EntityViewMode::create([ - 'targetEntityType' => 'post', - 'id' => 'post.featured', - 'status' => TRUE, - 'label' => t('Featured'), - ])->save(); - } - - // Create view display for post bundle of Post entity. - if (!EntityViewDisplay::load('post.post.featured')) { - $display = EntityViewDisplay::load('post.post.default')->toArray(); - unset( - $display['content']['field_post_comments'], - $display['hidden']['like_and_dislike'] - ); - $display['content']['like_and_dislike'] = [ - 'weight' => 3, - 'region' => 'content', - ]; - $display = array_merge($display, [ - 'uuid' => NULL, - '_core' => NULL, - 'targetEntityType' => 'post', - 'mode' => 'featured', - ]); - EntityViewDisplay::create($display)->save(); - } -} - -/** - * Update likes in post activity and comment view modes. - */ -function social_post_update_8901() { - /** @var \Drupal\update_helper\Updater $updateHelper */ - $updateHelper = \Drupal::service('update_helper.updater'); - - // Execute configuration update definitions with logging of success. - $updateHelper->executeUpdate('social_post', 'social_post_update_8901'); - - // Output logged messages to related channel of update execution. - return $updateHelper->logger()->output(); -}