Skip to content

Commit

Permalink
Add Translator to SitemapPresenter to use current locale on the cache…
Browse files Browse the repository at this point in the history
… key in order to generate l10n sitemap content. Fix renderData method in Builder class missing transformer parameter
  • Loading branch information
veve40 committed Oct 25, 2023
1 parent ce68156 commit e3346c4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Charcoal/Sitemap/Service/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ protected function renderData(ViewableInterface $obj, $data, $transformer = null
if (is_array($data)) {
$out = [];
foreach ($data as $key => $content) {
$out[$key] = $this->renderData($obj, $content);
$out[$key] = $this->renderData($obj, $content, $transformer);
}
return $out;
}
Expand Down
11 changes: 8 additions & 3 deletions src/Charcoal/Sitemap/Service/SitemapPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ArrayAccess;
use Charcoal\Cache\Facade\CachePoolFacade;
use Charcoal\Factory\FactoryInterface;
use Charcoal\Translator\TranslatorAwareTrait;
use InvalidArgumentException;
use Traversable;

Expand All @@ -20,6 +21,8 @@
*/
class SitemapPresenter
{
use TranslatorAwareTrait;

/**
* @var FactoryInterface $transformer
*/
Expand All @@ -40,10 +43,11 @@ class SitemapPresenter
* @param string $getterPattern The string pattern to match string with. Must have a single
* catch-block.
*/
public function __construct($transformerFactory, $cacheFacade, $getterPattern = '~{{(\w*?)}}~')
public function __construct($transformerFactory, $cacheFacade, $translator, $getterPattern = '~{{(\w*?)}}~')
{
$this->setCacheFacade($cacheFacade);
$this->setTransformerFactory($transformerFactory);
$this->setTranslator($translator);
$this->getterPattern = $getterPattern;
}

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

$key = sprintf(
'%s_%s_%s',
'%s_%s_%s_%s',
get_class($transformer),
$obj->objType(),
$obj->id()
$obj->id(),
$this->translator()->getLocale(),
);

$that = $this;
Expand Down
18 changes: 11 additions & 7 deletions src/Charcoal/Sitemap/ServiceProvider/SitemapServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public function register(Container $container)

return new SitemapPresenter(
$transformerFactory,
$container['cache/facade']
$container['cache/facade'],
$container['translator'],
);
};
/**
Expand All @@ -73,12 +74,15 @@ public function register(Container $container)
'resolver_options' => [
'suffix' => 'Transformer',
'replacements' => [
'App/' => 'App/Transformer/Sitemap/',
'app/' => 'app/transformer/sitemap/',
'App\\' => 'App\\Transformer\\Sitemap\\',
'-' => '',
'/' => '\\',
'.' => '_'
'App/Model/' => 'App/Transformer/Sitemap/',
'app/model' => 'app/transformer/sitemap/',
'App\\Model\\' => 'App\\Transformer\\Sitemap\\',
'App/' => 'App/Transformer/Sitemap/',
'app/' => 'app/transformer/sitemap/',
'App\\' => 'App\\Transformer\\Sitemap\\',
'-' => '',
'/' => '\\',
'.' => '_'
],
],
]);
Expand Down

0 comments on commit e3346c4

Please sign in to comment.