Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom entity updater for AbstractTranslatableCustomEntity #92

Open
jotalops opened this issue Aug 13, 2017 · 0 comments
Open

custom entity updater for AbstractTranslatableCustomEntity #92

jotalops opened this issue Aug 13, 2017 · 0 comments
Assignees

Comments

@jotalops
Copy link

jotalops commented Aug 13, 2017

Pim\Bundle\CustomEntityBundle\Updater\Updater.php

the updateTranslation method is not working with AbstractTranslatableCustomEntity it would be....
( look at the third if )

protected function updateTranslation(ReferenceDataInterface $referenceData, $propertyPath, $value)
{
    $translationPattern = '/^(?<property>[a-zA-Z0-9_-]+)-(?<locale>[a-z]{2}_[A-Z]{2})$/';
    if (preg_match($translationPattern, $propertyPath, $matches)
        && (isset($matches['property']) && isset($matches['locale']))
    ) {
        if (!in_array($matches['locale'], $this->localeRepository->getActivatedLocaleCodes())) {
            throw new \InvalidArgumentException(
                sprintf('Locale "%s" is not activated', $matches['locale'])
            );
        }

        if(is_a($referenceData,'Pim\Bundle\CustomEntityBundle\Entity\AbstractTranslatableCustomEntity')){
            $translation = $referenceData->getTranslation($matches['locale']);
            if($this->propertyAccessor->isWritable($translation, $matches['property'])) {
                $referenceData->setLocale($matches['locale']);
                $this->propertyAccessor->setValue($translation, $matches['property'], $value);
            }

        } else {

            if ($this->propertyAccessor->isWritable($referenceData, $matches['property'])) {
                $referenceData->setLocale($matches['locale']);
                $this->propertyAccessor->setValue($referenceData, $matches['property'], $value);
            }
        }
    }

}
@jmleroux jmleroux self-assigned this Oct 5, 2017
@jmleroux jmleroux added the bug label Oct 5, 2017
@jmleroux jmleroux added this to the 2.0.7 milestone Nov 27, 2017
@fitn fitn removed this from the 2.0.7 milestone Mar 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants