Skip to content

Commit e3346c4

Browse files
committed
Add Translator to SitemapPresenter to use current locale on the cache key in order to generate l10n sitemap content. Fix renderData method in Builder class missing transformer parameter
1 parent ce68156 commit e3346c4

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/Charcoal/Sitemap/Service/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ protected function renderData(ViewableInterface $obj, $data, $transformer = null
360360
if (is_array($data)) {
361361
$out = [];
362362
foreach ($data as $key => $content) {
363-
$out[$key] = $this->renderData($obj, $content);
363+
$out[$key] = $this->renderData($obj, $content, $transformer);
364364
}
365365
return $out;
366366
}

src/Charcoal/Sitemap/Service/SitemapPresenter.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use ArrayAccess;
66
use Charcoal\Cache\Facade\CachePoolFacade;
77
use Charcoal\Factory\FactoryInterface;
8+
use Charcoal\Translator\TranslatorAwareTrait;
89
use InvalidArgumentException;
910
use Traversable;
1011

@@ -20,6 +21,8 @@
2021
*/
2122
class SitemapPresenter
2223
{
24+
use TranslatorAwareTrait;
25+
2326
/**
2427
* @var FactoryInterface $transformer
2528
*/
@@ -40,10 +43,11 @@ class SitemapPresenter
4043
* @param string $getterPattern The string pattern to match string with. Must have a single
4144
* catch-block.
4245
*/
43-
public function __construct($transformerFactory, $cacheFacade, $getterPattern = '~{{(\w*?)}}~')
46+
public function __construct($transformerFactory, $cacheFacade, $translator, $getterPattern = '~{{(\w*?)}}~')
4447
{
4548
$this->setCacheFacade($cacheFacade);
4649
$this->setTransformerFactory($transformerFactory);
50+
$this->setTranslator($translator);
4751
$this->getterPattern = $getterPattern;
4852
}
4953

@@ -59,10 +63,11 @@ public function transform($obj, $transformer = null)
5963
}
6064

6165
$key = sprintf(
62-
'%s_%s_%s',
66+
'%s_%s_%s_%s',
6367
get_class($transformer),
6468
$obj->objType(),
65-
$obj->id()
69+
$obj->id(),
70+
$this->translator()->getLocale(),
6671
);
6772

6873
$that = $this;

src/Charcoal/Sitemap/ServiceProvider/SitemapServiceProvider.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public function register(Container $container)
5454

5555
return new SitemapPresenter(
5656
$transformerFactory,
57-
$container['cache/facade']
57+
$container['cache/facade'],
58+
$container['translator'],
5859
);
5960
};
6061
/**
@@ -73,12 +74,15 @@ public function register(Container $container)
7374
'resolver_options' => [
7475
'suffix' => 'Transformer',
7576
'replacements' => [
76-
'App/' => 'App/Transformer/Sitemap/',
77-
'app/' => 'app/transformer/sitemap/',
78-
'App\\' => 'App\\Transformer\\Sitemap\\',
79-
'-' => '',
80-
'/' => '\\',
81-
'.' => '_'
77+
'App/Model/' => 'App/Transformer/Sitemap/',
78+
'app/model' => 'app/transformer/sitemap/',
79+
'App\\Model\\' => 'App\\Transformer\\Sitemap\\',
80+
'App/' => 'App/Transformer/Sitemap/',
81+
'app/' => 'app/transformer/sitemap/',
82+
'App\\' => 'App\\Transformer\\Sitemap\\',
83+
'-' => '',
84+
'/' => '\\',
85+
'.' => '_'
8286
],
8387
],
8488
]);

0 commit comments

Comments
 (0)