-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLangUrlTags.php
79 lines (63 loc) · 1.8 KB
/
LangUrlTags.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace Statamic\Addons\LangUrl;
use Statamic\Extend\Tags;
use Statamic\API\URL;
use Statamic\API\Data;
use Statamic\Data\Services\PagesService;
class LangUrlTags extends Tags
{
/**
* The {{ language_url }} tag
*
* @return string|array
*/
public function index()
{
//
$context = $this->context;
$url = "";
$route = "";
$slug = "";
$content_id = $context["id"];
$content_uri = $context["uri"];
$locale = $this->getParam('locale');
if($locale == "default"){
$test = Data::find($context["id"])->in("en");
$url = $test->uri();
return $url;
}
$contentObject = Data::find($context["id"])->in($locale);
$data = $contentObject->get()->dataForLocale($locale);
if( key_exists('slug',$data) ){
$slug = $data['slug'];
}
if( key_exists('is_entry',$context) ){
$collection = $context["collection"];
$collectionRoute = $context["settings"]["routes"]["collections"][$collection];
if( is_array($collectionRoute) ){
$route = $collectionRoute[$locale];
} elseif( is_string($collectionRoute) ) {
$route = $collectionRoute;
}
if($slug != ""){
$localized_url = str_replace("{slug}",$slug, $route );
}
}
if( key_exists('is_page',$context) ){
$localized_url = app(PagesService::class)
->localizedUris($locale)
->get($content_id, $content_uri );
}
$url = URL::prependSiteUrl($localized_url , $locale);
return $url ;
}
/**
* The {{ language_url:example }} tag
*
* @return string|array
*/
public function example()
{
//
}
}