You are here

protected function TwitterWidgetFormatter::getViewAll in Twitter Profile Widget 3.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/TwitterWidgetFormatter.php \Drupal\twitter_profile_widget\Plugin\Field\FieldFormatter\TwitterWidgetFormatter::getViewAll()

Helper function to prepare the "View all" link.

1 call to TwitterWidgetFormatter::getViewAll()
TwitterWidgetFormatter::viewElements in src/Plugin/Field/FieldFormatter/TwitterWidgetFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/TwitterWidgetFormatter.php, line 54

Class

TwitterWidgetFormatter
Plugin implementation of the 'twitter_widget' formatter.

Namespace

Drupal\twitter_profile_widget\Plugin\Field\FieldFormatter

Code

protected function getViewAll($instance) {
  if (!empty($instance['view_all'])) {
    if ($instance['list_type'] === 'search') {
      $params = [
        'q' => $instance['search'],
      ];
      $getfield = '?' . http_build_query($params);
      $url = Url::fromUri('https://twitter.com/search' . $getfield);
    }
    else {
      $url = Url::fromUri('https://twitter.com/' . $instance['account']);
    }
    return Link::fromTextAndUrl($instance['view_all'], $url);
  }
  return '';
}