Link to a View (with Contextual Filter value) If It Will Have Results (Drupal 8)
Returns a link render array.
1 2 3 4 5 6 7 |
$nid = $this->entity()->id(); $results = views_get_view_result('related_posts_by_category', 'page_1', $nid); if (!empty($results)) { $url = Url::fromRoute('view.related_posts_by_category.page_1', ['arg_0' => $nid]); $link = Link::fromTextAndUrl(t('Related Posts'), $url)->toRenderable(); return $link; } |