This repository has been archived by the owner on Sep 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementing alternate languages for content documents
fix other tests add first tests present current state fix bundle class create alternate_locale.enable flag fix file name fix provider creation changelog entry fix orm tests
- Loading branch information
1 parent
6626e63
commit ec65e44
Showing
18 changed files
with
545 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony CMF package. | ||
* | ||
* (c) 2011-2014 Symfony CMF | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Cmf\Bundle\SeoBundle; | ||
|
||
use Symfony\Cmf\Bundle\SeoBundle\Model\AlternateLocaleCollection; | ||
|
||
/** | ||
* An interface for providing alternate locale urls. | ||
* | ||
* @author Maximilian Berghoff <[email protected]> | ||
*/ | ||
interface AlternateLocaleProviderInterface | ||
{ | ||
/** | ||
* Creates a collection of AlternateLocales for one content object. | ||
* | ||
* @param object $content | ||
* @return AlternateLocaleCollection | ||
*/ | ||
public function createForContent($content); | ||
|
||
/** | ||
* Creates a collection of AlternateLocales for many content object. | ||
* | ||
* @param array|object[] $contents | ||
* @return AlternateLocaleCollection | ||
*/ | ||
public function createForManyContent(array $contents); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony CMF package. | ||
* | ||
* (c) 2011-2014 Symfony CMF | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Cmf\Bundle\SeoBundle\Model; | ||
|
||
/** | ||
* Value object for properties of an alternate locale. | ||
* | ||
* @author Maximilian Berghoff <[email protected]> | ||
*/ | ||
class AlternateLocale | ||
{ | ||
const REL = 'alternate'; | ||
|
||
/** | ||
* @var string The complete url for that locale. | ||
*/ | ||
public $href; | ||
|
||
/** | ||
* @var string The locale/language in the following formats: de, de-DE | ||
*/ | ||
public $hrefLocale; | ||
|
||
public function __construct($href, $hrefLocale) | ||
{ | ||
|
||
$this->href = $href; | ||
$this->hrefLocale = $hrefLocale; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony CMF package. | ||
* | ||
* (c) 2011-2014 Symfony CMF | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Cmf\Bundle\SeoBundle\Model; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
|
||
/** | ||
* Collection for alternate locales. | ||
* | ||
* @author Maximilian Berghoff <[email protected]> | ||
*/ | ||
class AlternateLocaleCollection extends ArrayCollection | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony CMF package. | ||
* | ||
* (c) 2011-2014 Symfony CMF | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Cmf\Bundle\SeoBundle; | ||
|
||
use Doctrine\Common\Persistence\ManagerRegistry; | ||
use Doctrine\ODM\PHPCR\DocumentManager; | ||
use Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface; | ||
use Symfony\Cmf\Bundle\SeoBundle\Model\AlternateLocale; | ||
use Symfony\Cmf\Bundle\SeoBundle\Model\AlternateLocaleCollection; | ||
use Symfony\Cmf\Component\Routing\RouteReferrersReadInterface; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
/** | ||
* This provider will be the default one for creating AlternateLocales | ||
* by the help of the phpcr-odm. | ||
* | ||
* @author Maximilian Berghoff <[email protected]> | ||
*/ | ||
class PhpcrAlternateLocaleProvider implements AlternateLocaleProviderInterface | ||
{ | ||
/** | ||
* @var UrlGeneratorInterface | ||
*/ | ||
private $urlGenerator; | ||
|
||
/** | ||
* @var ManagerRegistry | ||
*/ | ||
private $managerRegistry; | ||
|
||
/** | ||
* @param ManagerRegistry $managerRegistry | ||
* @param UrlGeneratorInterface $urlGenerator | ||
*/ | ||
public function __construct(ManagerRegistry $managerRegistry, UrlGeneratorInterface $urlGenerator) | ||
{ | ||
$this->managerRegistry = $managerRegistry; | ||
$this->urlGenerator = $urlGenerator; | ||
} | ||
|
||
/** | ||
* Creates a collection of AlternateLocales for one content object. | ||
* | ||
* @param object $content | ||
* @return AlternateLocaleCollection | ||
*/ | ||
public function createForContent($content) | ||
{ | ||
$documentManager = $this->getDocumentManagerForClass(get_class($content)); | ||
$alternateLocaleCollection = new AlternateLocaleCollection(); | ||
if (null === $documentManager | ||
|| !$content instanceof TranslatableInterface | ||
|| !$content instanceof RouteReferrersReadInterface | ||
) { | ||
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)), | ||
$locale | ||
) | ||
); | ||
} | ||
|
||
return $alternateLocaleCollection; | ||
} | ||
|
||
/** | ||
* Creates a collection of AlternateLocales for many content object. | ||
* | ||
* @param array|object[] $contents | ||
* @return AlternateLocaleCollection | ||
*/ | ||
public function createForManyContent(array $contents) | ||
{ | ||
// todo[max] implement for sitemap | ||
} | ||
|
||
/** | ||
* When the registry was set, this method figure out | ||
* the document manager of a given class. | ||
* | ||
* @param $class | ||
* @return DocumentManager|null|object | ||
*/ | ||
private function getDocumentManagerForClass($class) | ||
{ | ||
return $this->managerRegistry->getManagerForClass($class); | ||
} | ||
} |
Oops, something went wrong.