sonata-project / SonataTranslationBundle

SonataTranslationBundle
https://docs.sonata-project.org/projects/SonataTranslationBundle
MIT License
77 stars 69 forks source link

SonataTranslationBundles seems not to be working with sonata_type_collection form fields (while using PHPCR) #137

Closed syeo66 closed 4 years ago

syeo66 commented 8 years ago

Environment

Sonata packages

$ composer show sonata-project/*
sonata-project/admin-bundle                3.9.0
sonata-project/block-bundle                3.2.0
sonata-project/cache                       1.0.7
sonata-project/core-bundle                 3.1.1
sonata-project/datagrid-bundle             2.2
sonata-project/doctrine-extensions         1.0.2
sonata-project/doctrine-orm-admin-bundle   3.1.1
sonata-project/doctrine-phpcr-admin-bundle dev-master 829753e
sonata-project/easy-extends-bundle         2.1.10
sonata-project/exporter                    1.7.0
sonata-project/google-authenticator        1.0.2
sonata-project/translation-bundle          2.0.2
sonata-project/user-bundle                 3.0.1

Symfony packages

$ composer show symfony/*
symfony/assetic-bundle     v2.8.0  Integrates Assetic into Symfony2
symfony/intl               v3.1.5  A PHP replacement layer for the C intl e...
symfony/monolog-bundle     2.11.1  Symfony MonologBundle
symfony/phpunit-bridge     v2.8.12 Symfony PHPUnit Bridge
symfony/polyfill-apcu      v1.2.0  Symfony polyfill backporting apcu_* func...
symfony/polyfill-intl-icu  v1.2.0  Symfony polyfill for intl's ICU-related ...
symfony/polyfill-mbstring  v1.2.0  Symfony polyfill for the Mbstring extension
symfony/polyfill-php54     v1.2.0  Symfony polyfill backporting some PHP 5....
symfony/polyfill-php55     v1.2.0  Symfony polyfill backporting some PHP 5....
symfony/polyfill-php56     v1.2.0  Symfony polyfill backporting some PHP 5....
symfony/polyfill-php70     v1.2.0  Symfony polyfill backporting some PHP 7....
symfony/polyfill-util      v1.2.0  Symfony utilities for portability of PHP...
symfony/security-acl       v3.0.0  Symfony Security Component - ACL (Access...
symfony/swiftmailer-bundle v2.3.11 Symfony SwiftmailerBundle
symfony/symfony            v2.8.12 The Symfony PHP framework

PHP version

$ php -v
PHP 5.6.26 (cli) (built: Sep 21 2016 04:41:55)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

Subject

SonataTranslationBundles seems not to be working with sonata_type_collection form fields

Steps to reproduce

sonata_translation:
    locales: [ de, en, fr, it ]
    default_locale: de
    gedmo:
        enabled: false
    knplabs:
        enabled: false
    phpcr:
        enabled: true

sonata_admin:
    extensions:
        sonata_translation.admin.extension.phpcr_translatable:
            admins:
                - admin.facette
            implements:
                - Sonata\TranslationBundle\Model\Phpcr\TranslatableInterface

Create some Document classes

<?php

namespace AcmeBundle\Document;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\PHPCR\HierarchyInterface;
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;

/**
 * @PHPCR\Document(translator="attribute")
 */
class Facette
{
    // ...

   /**
     * @PHPCR\ReferenceMany(targetDocument="Textblock", strategy="weak", cascade={"persist"})
     * @var ArrayCollection
     */
    protected $textblocks;

    /**
     * @return ArrayCollection
     */
    public function getTextblocks()
    {
        return $this->textblocks;
    }

    /**
     * @param ArrayCollection $textblocks
     * @return mixed
     */
    public function setTextblocks(ArrayCollection $textblocks)
    {
        $this->textblocks = $textblocks;
        return $this;
    }

    /**
     * @param Textblock $textblock
     * @return mixed
     */
    public function addTextblock(Textblock $textblock)
    {
        if (!$this->textblocks->contains($textblock)) {
            $this->textblocks->add($textblock);
        }
        return $this;
    }

    /**
     * @param Textblock $textblock
     * @return mixed
     */
    public function removeTextblock(Textblock $textblock)
    {
        $this->textblocks->removeElement($textblock);
        return $this;
    }

    // ...
}
<?php

namespace AcmeBundle\Document;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\PHPCR\HierarchyInterface;
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;

/**
 * @PHPCR\Document(translator="attribute", referenceable=true)
 */
class Textblock
{
    // ...

    /**
     * The language this document currently is in
     * @PHPCR\Locale
     */
    protected $locale;

    /**
     * @PHPCR\Field(type="string", translated=true, nullable=true)
     * @var string
     */
    protected $description;

    public function setDescription($description)
    {
        $this->description = $description;
        return $this;
    }

    /**
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    // ...    
}

Create a form in Sonata Admin:

<?php

namespace AcmeBundle\Admin;

use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;

class FacetteAdmin extends AbstractPhpcrAdmin
{
    // ...

    /**
     * @param FormMapper $form
     */
    protected function configureFormFields(FormMapper $form)
    {
        $form
            ->add('textblocks', 'sonata_type_collection', array(
                    'label' => false,
                        ), array(
                    'edit' => 'inline',
                    'inline' => 'table',
                        //'sortable' => 'position',
                        //'limit' => 3
                ))
        ;
    }

    // ...
}

The textblocks are now acting as if they would not be translateable but should in fact be.

bhaktaraz commented 6 years ago

@syeo66 @jordisala1991 any updates for this issue?

syeo66 commented 6 years ago

@bhaktaraz To be honest I'm not even sure if this is even an issue anymore. I did not work on the project this happened in since more than a year and don't know if we worked around this (probably) or if it just vanished (probably not).

bhaktaraz commented 6 years ago

This is happening to me. I have 3 locales en, cn and sv. When I update the translations for en, its fine. But when I go and change the translations for cn, it changes the translations for en too. And I am not even using phpcr

stale[bot] commented 4 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.