You are here

public function SinglePageSiteManager::generateAnchor in Single Page Site 8

Same name and namespace in other branches
  1. 2.x src/Manager/SinglePageSiteManager.php \Drupal\single_page_site\Manager\SinglePageSiteManager::generateAnchor()
  2. 2.0.x src/Manager/SinglePageSiteManager.php \Drupal\single_page_site\Manager\SinglePageSiteManager::generateAnchor()

Generates a valid anchor.

Parameters

string $url: String with URL value.

Return value

mixed Return the Anchor filtered.

File

src/Manager/SinglePageSiteManager.php, line 186

Class

SinglePageSiteManager
Class SinglePageSiteManager.

Namespace

Drupal\single_page_site\Manager

Code

public function generateAnchor($url) {
  if ($this->settings
    ->get('filterurlprefix')) {
    $prefix = '';
    if ($this->languageNegotiation['source'] == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) {
      if (!empty($this->languageNegotiation['prefixes'][$this->currentLanguage])) {
        $prefix = $this->languageNegotiation['prefixes'][$this->currentLanguage] . '/';
      }
    }

    // Remove language url prefix.
    $url = preg_replace('#^/' . str_replace('#', '\\#', $prefix) . '#', '/', $url);
  }

  // Replace odd chars and leading slash.
  return str_replace(array(
    '/',
    '?q=',
  ), array(
    '_',
    '',
  ), substr($url, 1));
}