/** * {@inheritdoc} */ protected function createGuesser() { $collection = new AlternateLocaleCollection(); $collection->add(new AlternateLocale('http://symfony.com/fr', 'fr')); $localeProvider = $this->getMock('Symfony\\Cmf\\Bundle\\SeoBundle\\AlternateLocaleProviderInterface'); $localeProvider->expects($this->any())->method('createForContent')->with($this)->will($this->returnValue($collection)); return new AlternateLocalesGuesser($localeProvider); }
/** * Creates a collection of AlternateLocales for one content object. * * @param object $content * * @return AlternateLocaleCollection */ public function createForContent($content) { $alternateLocaleCollection = new AlternateLocaleCollection(); if (!$content instanceof TranslatableInterface || !$content instanceof RouteReferrersReadInterface) { return $alternateLocaleCollection; } $documentManager = $this->getDocumentManagerForClass(get_class($content)); if (null === $documentManager) { return $alternateLocaleCollection; } $alternateLocales = $documentManager->getLocalesFor($content); $currentLocale = $content->getLocale(); foreach ($alternateLocales as $locale) { if ($locale === $currentLocale) { continue; } $alternateLocaleCollection->add(new AlternateLocale($this->urlGenerator->generate($content, array('_locale' => $locale), true), $locale)); } return $alternateLocaleCollection; }