mirror of
https://github.com/silverstripe/silverstripe-translatable
synced 2024-10-22 09:05:59 +00:00
Update Translatable::MetaTags()
There was an issue which causes `No return tags` issue in hreflang tags added in pages when the page link contains get params. This link answer https://webmasters.stackexchange.com/questions/110458/how-to-avoid-hreflang-return-errors-with-url-that-contain-parameters?answertab=votes#tab-top suggests just add a canonical tag for the original page rather than adding hreflang tags.
This commit is contained in:
parent
22025df173
commit
7bed02e286
@ -1726,18 +1726,25 @@ class Translatable extends DataExtension implements PermissionProvider
|
|||||||
*/
|
*/
|
||||||
public function MetaTags(&$tags)
|
public function MetaTags(&$tags)
|
||||||
{
|
{
|
||||||
$template = '<link rel="alternate" type="text/html" title="%s" hreflang="%s" href="%s" />' . "\n";
|
if (
|
||||||
$translations = $this->owner->getTranslations();
|
($controller = Controller::curr())
|
||||||
if ($translations) {
|
&& count($controller->getRequest()->getVars())
|
||||||
$translations = $translations->toArray();
|
) {
|
||||||
$translations[] = $this->owner;
|
$tags .= '<link rel="canonical" href="'.$controller->AbsoluteLink().'" />';
|
||||||
|
} else {
|
||||||
|
$template = '<link rel="alternate" type="text/html" title="%s" hreflang="%s" href="%s" />' . "\n";
|
||||||
|
$translations = $this->owner->getTranslations();
|
||||||
|
if($translations->count()) {
|
||||||
|
$translations = $translations->toArray();
|
||||||
|
$translations[] = $this->owner;
|
||||||
|
|
||||||
foreach ($translations as $translation) {
|
foreach($translations as $translation) {
|
||||||
$tags .= sprintf($template,
|
$tags .= sprintf($template,
|
||||||
Convert::raw2xml($translation->Title),
|
Convert::raw2xml($translation->Title),
|
||||||
i18n::convert_rfc1766($translation->Locale),
|
i18n::convert_rfc1766($translation->Locale),
|
||||||
$translation->AbsoluteLink()
|
$translation->AbsoluteLink()
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user