Skip to content

Commit

Permalink
Merge 3.x into 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Jan 1, 2022
2 parents 4e90659 + d7c3112 commit 21ccf44
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [3.0.0-rc.1](https://github.com/sonata-project/SonataTranslationBundle/compare/3.0.0-alpha.1...3.0.0-rc.1) - 2021-12-31
### Added
- [[#572](https://github.com/sonata-project/SonataTranslationBundle/pull/572)] Added support for Symfony 6. ([@jordisala1991](https://github.com/jordisala1991))

### Changed
- [[#550](https://github.com/sonata-project/SonataTranslationBundle/pull/550)] `Sonata\TranslationBundle\Admin\Extension\Knplabs\TranslatableAdminExtension` has been marked as `@internal` ([@franmomu](https://github.com/franmomu))
- [[#550](https://github.com/sonata-project/SonataTranslationBundle/pull/550)] `Sonata\TranslationBundle\Admin\Extension\Gedmo\TranslatableAdminExtension` has been marked as `@internal` ([@franmomu](https://github.com/franmomu))

### Fixed
- [[#556](https://github.com/sonata-project/SonataTranslationBundle/pull/556)] Fixed accessing current locale from `block_locale_switcher.html.twig` template ([@ggabrovski](https://github.com/ggabrovski))

### Removed
- [[#599](https://github.com/sonata-project/SonataTranslationBundle/pull/599)] `UserLocaleSubscriber` class in favor of implementing its own solution ([@franmomu](https://github.com/franmomu))
- [[#558](https://github.com/sonata-project/SonataTranslationBundle/pull/558)] Dropped support for PHP 7.3 ([@franmomu](https://github.com/franmomu))
- [[#559](https://github.com/sonata-project/SonataTranslationBundle/pull/559)] Removed `TranslatableInterface::getLocale()` method ([@franmomu](https://github.com/franmomu))

## [2.10.1](https://github.com/sonata-project/SonataTranslationBundle/compare/2.10.0...2.10.1) - 2021-12-31
### Fixed
- [[#598](https://github.com/sonata-project/SonataTranslationBundle/pull/598)] Creating or updating an entity with translatable sub items ([@franmomu](https://github.com/franmomu))

## [2.10.0](https://github.com/sonata-project/SonataTranslationBundle/compare/2.9.1...2.10.0) - 2021-11-17
### Added
- [[#578](https://github.com/sonata-project/SonataTranslationBundle/pull/578)] Support for 5.x versions in `symfony/browser-kit`, `symfony/config`, `symfony/css-selector`, `symfony/dependency-injection`, `symfony/http-foundation`, `symfony/intl`, `symfony/options-resolver`, `symfony/phpunit-bridge` and `symfony/templating` ([@phansys](https://github.com/phansys))
Expand Down
14 changes: 9 additions & 5 deletions src/Admin/Extension/Gedmo/TranslatableAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ public function alterObject(AdminInterface $admin, object $object): void
return;
}

$objectManager = $this->managerRegistry->getManagerForClass(\get_class($object));

\assert($objectManager instanceof ObjectManager);

$objectManager->refresh($object);
$this->setLocale($object);
}

Expand Down Expand Up @@ -102,6 +97,15 @@ private function setLocale(object $object): void

$reflectionProperty = $reflClass->getProperty($configuration['locale']);
$reflectionProperty->setAccessible(true);

if ($reflectionProperty->getValue($object) === $translatableLocale) {
return;
}

$reflectionProperty->setValue($object, $translatableLocale);

if ($objectManager->contains($object)) {
$objectManager->refresh($object);
}
}
}
31 changes: 30 additions & 1 deletion tests/Admin/Extension/Gedmo/TranslatableAdminExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public function get(): string
public function testSetLocaleForTranslatableObject(): void
{
$object = new ModelTranslatable();
$this->em->persist($object);

$this->extension->alterNewInstance($this->admin, $object);

Expand Down Expand Up @@ -113,6 +112,36 @@ public function testConfigureQuery(): void
static::assertFalse($this->translatableListener->getTranslationFallback());
}

public function testObjectIsRefreshedWithDifferentLocale(): void
{
$object = new ModelTranslatable();
$object->locale = 'en';
$this->em->persist($object);
$this->em->flush();

$object->refreshableField = 'new value';

$this->extension->alterObject($this->admin, $object);

/** @psalm-suppress TypeDoesNotContainType */
static::assertSame('', $object->refreshableField);
}

public function testObjectIsNotRefreshedWithTheSameLocale(): void
{
$object = new ModelTranslatable();
$object->locale = 'es';
$this->em->persist($object);
$this->em->flush();

$object->refreshableField = 'new value';

$this->extension->alterObject($this->admin, $object);

/** @psalm-suppress RedundantCondition */
static::assertSame('new value', $object->refreshableField);
}

protected function getUsedEntityFixtures(): array
{
return [ModelTranslatable::class];
Expand Down
5 changes: 5 additions & 0 deletions tests/Fixtures/Model/ModelTranslatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ class ModelTranslatable implements Translatable
* @Gedmo\Locale()
*/
public ?string $locale = null;

/**
* @ORM\Column(type="string", length=10)
*/
public string $refreshableField = '';
}

0 comments on commit 21ccf44

Please sign in to comment.