You are here

function _social_post_mass_update_helper in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_helper()
  2. 8.3 modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_helper()
  3. 8.4 modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_helper()
  4. 8.5 modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_helper()
  5. 8.6 modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_helper()
  6. 8.7 modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_helper()
  7. 8.8 modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_helper()
  8. 10.0.x modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_helper()
  9. 10.1.x modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_helper()
  10. 10.2.x modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_helper()

Updates individual posts when fewer than 10 are queued.

Parameters

\Drupal\social_post\Entity\PostInterface $post: A post to update.

array $updates: Associative array of updates.

string $langcode: (optional) The language updates should be applied to. If none is specified all available languages are processed.

Return value

\Drupal\social_post\Entity\PostInterface An updated post object.

See also

social_post_mass_update()

2 calls to _social_post_mass_update_helper()
social_post_mass_update in modules/social_features/social_post/social_post.admin.inc
Updates all posts in the passed-in array with the passed-in field values.
_social_post_mass_update_batch_process in modules/social_features/social_post/social_post.admin.inc
Implements callback_batch_operation().

File

modules/social_features/social_post/social_post.admin.inc, line 81
Helper methods for post administration actions.

Code

function _social_post_mass_update_helper(PostInterface $post, array $updates, $langcode = NULL) {
  $langcodes = isset($langcode) ? [
    $langcode,
  ] : array_keys($post
    ->getTranslationLanguages());

  // For efficiency manually save the original post before applying any changes.
  $post->original = clone $post;
  foreach ($langcodes as $langcode) {
    foreach ($updates as $name => $value) {
      $post
        ->getTranslation($langcode)->{$name} = $value;
    }
  }
  $post
    ->save();
  return $post;
}