Example #1
0
 /**
  * Подставить сегмент языка в ссылку
  * @param string $path
  * @param $locale
  * @return string
  */
 public function filterLocaleLink($path, $locale = null)
 {
     if (strpos($path, 'http://') === 0 || strpos($path, 'https://') === 0) {
         return $path;
     }
     if ($locale) {
         $office = $this->officeManager->getByLocale($locale);
     } else {
         $office = $this->officeManager->getCurrentOffice();
         if (!$office) {
             $office = $this->officeManager->getDefault();
         }
     }
     if (empty($this->offices)) {
         $this->offices = $this->officeManager->getRoutingOffices();
     }
     $languages = array_keys($this->offices);
     $resultUrl = $path;
     if ($office->getIncludeLangInUrl()) {
         $arrPath = explode('/', ltrim($path, '/'));
         if (empty($arrPath[0]) || !in_array($arrPath[0], $languages)) {
             $resultUrl = '/' . $office->getDefaultLanguage() . '/' . ltrim($path, '/');
         }
     }
     return $resultUrl;
 }