Skip to content

Commit

Permalink
Implement PHPCR
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Bastien committed Mar 6, 2014
1 parent 2b79b3d commit 840a3ef
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Admin/Extension/AbstractTranslatableAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ abstract class AbstractTranslatableAdminExtension extends AdminExtension
*/
const TRANSLATABLE_LOCALE_PARAMETER = 'tl';

/**
* @var string
*/
protected $translatableLocale;

/**
* @return ContainerInterface
*/
Expand Down
5 changes: 0 additions & 5 deletions Admin/Extension/Gedmo/TranslatableAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ class TranslatableAdminExtension extends AbstractTranslatableAdminExtension
*/
protected $translatableListener;

/**
* @var string
*/
protected $translatableLocale;

/**
* @return TranslatableListener
*/
Expand Down
42 changes: 42 additions & 0 deletions Admin/Extension/Phpcr/TranslatableAdminExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/*
* This file is part of the Sonata package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\TranslationBundle\Admin\Extension\Phpcr;

use Doctrine\ODM\PHPCR\DocumentManager;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\TranslationBundle\Admin\Extension\AbstractTranslatableAdminExtension;

/**
* @author Nicolas Bastien <[email protected]>
*/
class TranslatableAdminExtension extends AbstractTranslatableAdminExtension
{
/**
* @param AdminInterface $admin
*
* @return DocumentManager
*/
protected function getDocumentManager(AdminInterface $admin)
{
return $admin->getModelManager()->getDocumentManager();
}

/**
* {@inheritdoc}
*/
public function alterObject(AdminInterface $admin, $object)
{
$locale = $this->getTranslatableLocale($admin);

if ($this->isTranslatable($object) && ($object->getLocale() != $locale)) {
$object = $this->getDocumentManager($admin)->findTranslation($admin->getClass(), $object->getId(), $locale);
}
}
}
21 changes: 21 additions & 0 deletions Model/Phpcr/TranslatableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/*
* This file is part of the Sonata project.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\TranslationBundle\Model\Phpcr;

use Sonata\TranslationBundle\Model\TranslatableInterface as GenericTranslatableInterface;

/**
* This is a Convenient interface made to easily plug PHPCR admin extension on models
*
* @author Nicolas Bastien <[email protected]>
*/
interface TranslatableInterface extends GenericTranslatableInterface
{
}
4 changes: 4 additions & 0 deletions Resources/config/admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@

<parameters>
<parameter key="sonata_translation.admin.extension.gedmo_translatable.class">Sonata\TranslationBundle\Admin\Extension\Gedmo\TranslatableAdminExtension</parameter>
<parameter key="sonata_translation.admin.extension.phpcr_translatable.class">Sonata\TranslationBundle\Admin\Extension\Phpcr\TranslatableAdminExtension</parameter>
</parameters>

<services>
<service id="sonata_translation.admin.extension.gedmo_translatable" class="%sonata_translation.admin.extension.gedmo_translatable.class%">
<tag name="sonata.admin.extension" />
</service>
<service id="sonata_translation.admin.extension.phpcr_translatable" class="%sonata_translation.admin.extension.phpcr_translatable.class%">
<tag name="sonata.admin.extension" />
</service>
</services>

</container>
3 changes: 3 additions & 0 deletions Resources/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ sonata_admin:
sonata_translation.admin.extension.gedmo_translatable:
extends:
- Sonata\TranslationBundle\Model\Gedmo\AbstractTranslatable
sonata_translation.admin.extension.phpcr_translatable:
implements:
- Sonata\TranslationBundle\Model\Phpcr\TranslatableInterface

0 comments on commit 840a3ef

Please sign in to comment.