Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Jul 28, 2019
2 parents 9ea162a + 0c6cbc3 commit 5a72378
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,13 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [3.10.0](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/compare/3.9.0...3.10.0) - 2019-07-20
### Added
- Don't hide edit button `sonata_type_model_list_widget` if there is no value

### Fixed
- Use a more reliable method for represent composite identifiers in a string

## [3.9.0](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/compare/3.8.3...3.9.0) - 2019-04-17
### Added
- Added support for protected (no public constructor) entity creation
Expand Down
21 changes: 14 additions & 7 deletions src/Model/ModelManager.php
Expand Up @@ -16,6 +16,7 @@
use Doctrine\Common\Util\ClassUtils;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\LockMode;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\ClassMetadata;
Expand Down Expand Up @@ -339,16 +340,10 @@ public function getIdentifierValues($entity)
continue;
}

if (method_exists($value, '__toString')) {
$identifiers[] = (string) $value;

continue;
}

$fieldType = $metadata->getTypeOfField($name);
$type = $fieldType && Type::hasType($fieldType) ? Type::getType($fieldType) : null;
if ($type) {
$identifiers[] = $type->convertToDatabaseValue($value, $platform);
$identifiers[] = $this->getValueFromType($value, $type, $fieldType, $platform);

continue;
}
Expand Down Expand Up @@ -633,4 +628,16 @@ protected function camelize($property)
{
return str_replace(' ', '', ucwords(str_replace('_', ' ', $property)));
}

/**
* @param mixed $value
*/
private function getValueFromType($value, Type $type, string $fieldType, AbstractPlatform $platform): string
{
if ('binary' === $platform->getDoctrineTypeMapping($fieldType)) {
return (string) $type->convertToPHPValue($value, $platform);
}

return $type->convertToDatabaseValue($value, $platform);
}
}
50 changes: 50 additions & 0 deletions tests/Fixtures/DoctrineType/UuidBinaryType.php
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\DoctrineORMAdminBundle\Tests\Fixtures\DoctrineType;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\StringType;
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Util\NonIntegerIdentifierTestClass;

/**
* Mock for a custom doctrine type used in the ModelManagerTest suite.
*
* @author Jorge Garces <jgarces@iberdat.com>
*/
final class UuidBinaryType extends StringType
{
const NAME = 'uuid_binary';

/**
* {@inheritdoc}
*/
public function getName()
{
return self::NAME;
}

/**
* {@inheritdoc}
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
return !empty($value) ? new NonIntegerIdentifierTestClass($value->toString()) : null;
}

/**
* {@inheritdoc}
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
return $value->toString();
}
}
4 changes: 4 additions & 0 deletions tests/Model/ModelManagerTest.php
Expand Up @@ -37,6 +37,7 @@
use Sonata\DoctrineORMAdminBundle\Datagrid\OrderByToSelectWalker;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery;
use Sonata\DoctrineORMAdminBundle\Model\ModelManager;
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\DoctrineType\UuidBinaryType;
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\DoctrineType\UuidType;
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\AbstractEntity;
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\AssociatedEntity;
Expand All @@ -57,6 +58,9 @@ public static function setUpBeforeClass(): void
if (!Type::hasType('uuid')) {
Type::addType('uuid', UuidType::class);
}
if (!Type::hasType('uuid_binary')) {
Type::addType('uuid_binary', UuidBinaryType::class);
}
}

public function testSortParameters(): void
Expand Down

0 comments on commit 5a72378

Please sign in to comment.