Sterc / SEOTab

SEO assistance for MODX — Optimize your MODX Revolution pages for the best Search Engine performance. Follow https://twitter.com/sterc for tips and updates.
https://www.sterc.com/modx/extras/
25 stars 31 forks source link

unnecessary switchContext in stercseo.class.php #202

Closed dtgeorge closed 3 years ago

dtgeorge commented 3 years ago

function getAlternateLinks has unnecessary conext switch ($this->modx->switchContext($contextKey);), that could be the reason for inappropriate behavior.

In some cases (when some resources has no translation in some contexts), the context is fixed in the wrong state, as a result of which in the following cycles within sitemap() functionn we get the wrong (empty) result of the function makeUrl.

Solution (tested) is:

$alternates = []; $translations = $babel->getLinkedResources($resource->get('id')); foreach ($translations as $contextKey => $resourceId) { //$this->modx->switchContext($contextKey); $alternates[] = $this->getChunk($options['alternateTpl'], array( 'cultureKey' => $this->modx->getOption('cultureKey', ['context_key' => $contextKey], 'en'), //'url' => $this->modx->makeUrl($resourceId, '', '', 'full') 'url' => $this->modx->makeUrl($resourceId, $contextKey, '', 'full') )); } return implode(PHP_EOL, $alternates);