You are here

protected function JsonFeedSerializer::getFeedHomePageUrl in JSON Feed 8

The URL of the feed.

1 call to JsonFeedSerializer::getFeedHomePageUrl()
JsonFeedSerializer::render in src/Plugin/views/style/JsonFeedSerializer.php
Render the display in this style.

File

src/Plugin/views/style/JsonFeedSerializer.php, line 245

Class

JsonFeedSerializer
Default style plugin to render a JSON feed.

Namespace

Drupal\json_feed\Plugin\views\style

Code

protected function getFeedHomePageUrl() {

  // Figure out which display which has a path we're using for this feed. If
  // there isn't one, use the global $base_url.
  $link_display_id = $this->view->display_handler
    ->getLinkDisplay();
  if ($link_display_id && ($display = $this->view->displayHandlers
    ->get($link_display_id))) {
    $url = $this->view
      ->getUrl(NULL, $link_display_id);
  }
  $url_options = [
    'absolute' => TRUE,
  ];
  $base_url = Url::fromRoute('<front>')
    ->setAbsolute()
    ->toString();

  /** @var \Drupal\Core\Url $url */
  if ($url) {

    // Compare the link to the default home page; if it's the default home
    // page, just use $base_url.
    $config = \Drupal::config('system.site');
    $url_string = $url
      ->setOptions($url_options)
      ->toString();
    if ($url_string === Url::fromUserInput($config
      ->get('page.front'))
      ->toString()) {
      $url_string = $base_url;
    }
    return $url_string;
  }
  return $base_url;
}