You are here

public function SocialActivityLazyBuilder::viewsLazyBuild in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_activity/src/SocialActivityLazyBuilder.php \Drupal\social_activity\SocialActivityLazyBuilder::viewsLazyBuild()
  2. 10.0.x modules/social_features/social_activity/src/SocialActivityLazyBuilder.php \Drupal\social_activity\SocialActivityLazyBuilder::viewsLazyBuild()
  3. 10.1.x modules/social_features/social_activity/src/SocialActivityLazyBuilder.php \Drupal\social_activity\SocialActivityLazyBuilder::viewsLazyBuild()
  4. 10.2.x modules/social_features/social_activity/src/SocialActivityLazyBuilder.php \Drupal\social_activity\SocialActivityLazyBuilder::viewsLazyBuild()

Returns views render for lazy builder.

Parameters

string $view_id: The views ID.

string $display_id: The views display ID.

string $node_type: Node bundle.

int $item_per_page: Items to display.

string|null $vocabulary: Vocabulary ID.

mixed $tags: List of tags IDs.

Return value

array|null Render array.

File

modules/social_features/social_activity/src/SocialActivityLazyBuilder.php, line 69

Class

SocialActivityLazyBuilder
Class SocialActivityLazyBuilder.

Namespace

Drupal\social_activity

Code

public function viewsLazyBuild($view_id, $display_id, $node_type, $item_per_page, $vocabulary = NULL, ...$tags) {

  // Get view.
  $view_entity = $this->entityTypeManager
    ->getStorage('view')
    ->load($view_id);
  $view = $this->viewExecutable
    ->get($view_entity);
  $view
    ->setDisplay($display_id);
  $view
    ->setItemsPerPage($item_per_page);

  // Add filtration if tags and vocabulary exists.
  if ($vocabulary && $vocabulary !== '_none' && !empty($tags)) {
    $view->filter_tags = $tags;
    $view->filter_vocabulary = $vocabulary;
  }
  $view
    ->preExecute();
  $view
    ->execute($display_id);

  // Change entity display and add attachments if views block in dashboard.
  if ($view
    ->id() == "activity_stream" && $node_type === 'dashboard') {
    $view->rowPlugin->options['view_mode'] = 'featured';
    $view->element['#attached']['library'][] = 'social_featured_content/paragraph.featured';
  }

  // Get views content.
  $content = $view
    ->render($display_id);
  return $content;
}