forked from udokmeci/yii2-seo-i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinksGenerator.php
48 lines (40 loc) · 1.49 KB
/
LinksGenerator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace udokmeci\yii2SeoI18n;
use Yii;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
class LinksGenerator extends BaseSeoGenerator
{
public $locale_param='locale';
public $defaults=[
'canonical'=>'',
'icon'=>'',
];
public $_all=[];
public function init()
{
$this->_all=
ArrayHelper::merge(
$this->defaults,
$this->site->getSeoData(),
(array)$this->item->getSeoData()
);
return parent::init();
}
public function render()
{
$outputs='';
foreach ($this->site->getSeoLocales() as $locale => $name) {
$outputs.='<link rel="alternate" hreflang="'. substr($locale,0,2) .'" href="'. Url::to(['/'.\Yii::$app->requestedRoute] + ['locale' => $locale] + \Yii::$app->getRequest()->getQueryParams(), true) .'" />';
}
$outputs.='<link rel="alternate" hreflang="x-default" href="'. Url::to(['/'.\Yii::$app->requestedRoute] + ['locale' => $this->site->getSeoData()->defaultLocale ] + \Yii::$app->getRequest()->getQueryParams(), false).'" />';
if (isset($this->item->getSeoData()->canonicalUrl)) {
$outputs.='<link rel="canonical" href="'. $this->item->getSeoData()->canonicalUrl .'" />';
}
if (isset($this->site->getSeoData()->icon)) {
$outputs.='<link rel="shortcut icon" type="image/x-icon" href="'. $this->site->getSeoData()->icon .'" />';
}
return $outputs;
}
}