You are here

function social_post_mass_update 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()
  2. 8.3 modules/social_features/social_post/social_post.admin.inc \social_post_mass_update()
  3. 8.4 modules/social_features/social_post/social_post.admin.inc \social_post_mass_update()
  4. 8.5 modules/social_features/social_post/social_post.admin.inc \social_post_mass_update()
  5. 8.6 modules/social_features/social_post/social_post.admin.inc \social_post_mass_update()
  6. 8.7 modules/social_features/social_post/social_post.admin.inc \social_post_mass_update()
  7. 8.8 modules/social_features/social_post/social_post.admin.inc \social_post_mass_update()
  8. 10.0.x modules/social_features/social_post/social_post.admin.inc \social_post_mass_update()
  9. 10.1.x modules/social_features/social_post/social_post.admin.inc \social_post_mass_update()
  10. 10.2.x modules/social_features/social_post/social_post.admin.inc \social_post_mass_update()

Updates all posts in the passed-in array with the passed-in field values.

IMPORTANT NOTE: This function is intended to work when called from a form submission handler. Calling it outside of the form submission process may not work correctly.

Parameters

array $posts: Array of post ids or posts to update.

array $updates: Array of key/value pairs with post field names and the value to update that field to.

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

bool $load: (optional) TRUE if $posts contains an array of post IDs to be loaded, FALSE if it contains fully loaded posts. Defaults to FALSE.

1 call to social_post_mass_update()
social_post_user_cancel in modules/social_features/social_post/social_post.module
Implements hook_user_cancel().

File

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

Code

function social_post_mass_update(array $posts, array $updates, $langcode = NULL, $load = FALSE) {

  // We use batch processing to prevent timeout when updating a large number
  // of posts.
  if (count($posts) > 10) {
    $batch = [
      'operations' => [
        [
          '_social_post_mass_update_batch_process',
          [
            $posts,
            $updates,
            $langcode,
            $load,
          ],
        ],
      ],
      'finished' => '_social_post_mass_update_batch_finished',
      'title' => t('Processing'),
      // We use a single multi-pass operation, so the default
      // 'Remaining x of y operations' message will be confusing here.
      'progress_message' => '',
      'error_message' => t('The update has encountered an error.'),
      // The operations do not live in the .module file, so we need to
      // tell the batch engine which file to load before calling them.
      'file' => drupal_get_path('module', 'social_post') . '/social_post.admin.inc',
    ];
    batch_set($batch);
  }
  else {
    $storage = \Drupal::entityTypeManager()
      ->getStorage('post');
    if ($load) {
      $posts = $storage
        ->loadMultiple($posts);
    }
    foreach ($posts as $post) {
      _social_post_mass_update_helper($post, $updates, $langcode);
    }
    \Drupal::messenger()
      ->addStatus(t('The update has been performed.'));
  }
}