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 2, 2020
2 parents 75c36b6 + af25c1c commit 4386d7d
Show file tree
Hide file tree
Showing 19 changed files with 309 additions and 76 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/documentation.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# DO NOT EDIT THIS FILE!
#
# It's auto-generated by sonata-project/dev-kit package.

on:
push:
paths:
Expand Down Expand Up @@ -31,7 +35,7 @@ jobs:
run: sudo apt-get install python-dev build-essential

- name: "Cache pip"
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('docs/requirements.txt') }}
Expand Down
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,39 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [3.20.0](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/compare/3.19.0...3.20.0) - 2020-06-30
### Added
- [[#1057](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1057)]
Add `StringFilter` support for `START_WITH` and `END_WITH` operator
([@napestershine](https://github.com/napestershine))
- [[#1049](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1049)]
Added `FieldDescription::getTargetModel()`.
([@phansys](https://github.com/phansys))

### Deprecated
- [[#1049](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1049)] Deprecated passing `null` as argument 2 for `ModelManager::find()`; ([@phansys](https://github.com/phansys))
- [[#1049](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1049)] Deprecated passing `null` as argument 1 for `ModelManager::getNormalizedIdentifier()`; ([@phansys](https://github.com/phansys))
- [[#1049](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1049)] Deprecated passing objects which are in state 2 (new) or 4 (removed) as argument 1 for `ModelManager::getNormalizedIdentifier()`; ([@phansys](https://github.com/phansys))
- [[#1049](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1049)] Deprecated passing other type than `object` as argument 1 for `ModelManager::getUrlSafeIdentifier()`; ([@phansys](https://github.com/phansys))
- [[#1049](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1049)] Deprecated `FieldDescription::getTargetEntity()` in favor of `FieldDescription::getTargetModel()`. ([@phansys](https://github.com/phansys))

## [3.19.0](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/compare/3.18.0...3.19.0) - 2020-06-26
### Changed
- [[#1055](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1055)]
`decimal` and `float` type use the `float` template if no `number` template
exists ([@VincentLanglet](https://github.com/VincentLanglet))

### Fixed
- [[#1055](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1055)]
`one_to_one`, `one_to_many`, `many_to_one` and `many_to_many` type are
correctly using the template defined in your config instead of the Sonata one.
([@VincentLanglet](https://github.com/VincentLanglet))

### Removed
- [[#1048](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1048)]
Remove SonataCoreBundle dependencies
([@wbloszyk](https://github.com/wbloszyk))

## [3.18.0](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/compare/3.17.1...3.18.0) - 2020-06-02
### Added
- Added direct dependency against "twig/twig".
Expand Down
17 changes: 15 additions & 2 deletions UPGRADE-3.x.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
UPGRADE 3.x
===========

UPGRADE FROM 3.19 to 3.20
=========================

### Sonata\DoctrineORMAdminBundle\Admin\FieldDescription

Deprecated `getTargetEntity()`, use `getTargetModel()` instead.

### Sonata\DoctrineORMAdminBundle\Model\ModelManager

Deprecated passing `null` as argument 2 for `find()`.
Deprecated passing `null` or an object which is in state new or removed as argument 1 for `getNormalizedIdentifier()`.
Deprecated passing `null` as argument 1 for `getUrlSafeIdentifier()`.

UPGRADE FROM 3.0 to 3.1
=======================

### Tests

All files under the ``Tests`` directory are now correctly handled as internal test classes.
You can't extend them anymore, because they are only loaded when running internal tests.
All files under the ``Tests`` directory are now correctly handled as internal test classes.
You can't extend them anymore, because they are only loaded when running internal tests.
More information can be found in the [composer docs](https://getcomposer.org/doc/04-schema.md#autoload-dev).
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"doctrine/doctrine-bundle": "^1.8 || ^2.0",
"doctrine/orm": "^2.5",
"doctrine/persistence": "^1.3.4",
"sonata-project/admin-bundle": "^3.63",
"sonata-project/admin-bundle": "^3.71",
"sonata-project/exporter": "^1.11.0 || ^2.0",
"sonata-project/form-extensions": "^0.1 || ^1.4",
"symfony/config": "^4.4",
Expand All @@ -44,7 +44,8 @@
},
"conflict": {
"simplethings/entity-audit-bundle": ">=2.0",
"sonata-project/block-bundle": "<3.11"
"sonata-project/block-bundle": "<3.11",
"sonata-project/core-bundle": "<3.20"
},
"provide": {
"sonata-project/admin-bundle-persistency-layer": "1.0.0"
Expand Down
5 changes: 4 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Sphinx!=1.8.0
# DO NOT EDIT THIS FILE!
#
# It's auto-generated by sonata-project/dev-kit package.
Sphinx==1.8.5
git+https://github.com/fabpot/sphinx-php.git
sphinx_rtd_theme
22 changes: 22 additions & 0 deletions src/Admin/FieldDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,33 @@ public function setAssociationMapping($associationMapping): void
$this->fieldName = $associationMapping['fieldName'];
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since sonata-project/doctrine-orm-admin-bundle 3.20 and will be removed in version 4.0. Use FieldDescription::getTargetModel() instead.
*/
public function getTargetEntity()
{
@trigger_error(sprintf(
'Method %s() is deprecated since sonata-project/doctrine-orm-admin-bundle 3.20 and will be removed in version 4.0.'
.' Use %s::getTargetModel() instead.',
__METHOD__,
__CLASS__
), E_USER_DEPRECATED);

return $this->getTargetModel();
}

/**
* @final since sonata-project/doctrine-orm-admin-bundle 3.20.
*/
public function getTargetModel(): ?string
{
if ($this->associationMapping) {
return $this->associationMapping['targetEntity'];
}

return null;
}

public function setFieldMapping($fieldMapping): void
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/DatagridBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function addFilter(DatagridInterface $datagrid, $type, FieldDescriptionIn

if (ModelAutocompleteFilter::class === $type) {
$fieldDescription->mergeOption('field_options', [
'class' => $fieldDescription->getTargetEntity(),
'class' => $fieldDescription->getTargetModel(),
'model_manager' => $fieldDescription->getAdmin()->getModelManager(),
'admin_code' => $admin->getCode(),
'context' => 'filter',
Expand Down
8 changes: 4 additions & 4 deletions src/Builder/FormContractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip
));
}

$options['class'] = $fieldDescription->getTargetEntity();
$options['class'] = $fieldDescription->getTargetModel();
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();

if ($this->checkFormClass($type, [ModelAutocompleteType::class])) {
Expand All @@ -122,7 +122,7 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip
'The current field `%s` is not linked to an admin.'
.' Please create one for the target entity: `%s`',
$fieldDescription->getName(),
$fieldDescription->getTargetEntity()
$fieldDescription->getTargetModel()
));
}
}
Expand All @@ -132,7 +132,7 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip
'The current field `%s` is not linked to an admin.'
.' Please create one for the target entity : `%s`',
$fieldDescription->getName(),
$fieldDescription->getTargetEntity()
$fieldDescription->getTargetModel()
));
}

Expand Down Expand Up @@ -165,7 +165,7 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip
'The current field `%s` is not linked to an admin.'
.' Please create one for the target entity : `%s`',
$fieldDescription->getName(),
$fieldDescription->getTargetEntity()
$fieldDescription->getTargetModel()
));
}

Expand Down
20 changes: 18 additions & 2 deletions src/Builder/ListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Sonata\AdminBundle\Builder\ListBuilderInterface;
use Sonata\AdminBundle\Guesser\TypeGuesserInterface;
use Sonata\DoctrineORMAdminBundle\Guesser\TypeGuesser;

class ListBuilder implements ListBuilderInterface
{
Expand Down Expand Up @@ -192,12 +193,27 @@ public function buildActionFieldDescription(FieldDescriptionInterface $fieldDesc
/**
* @param string $type
*
* @return string
* @return string|null
*/
private function getTemplate($type)
{
if (!isset($this->templates[$type])) {
return;
// NEXT_MAJOR: Remove the check for deprecated type and always return null.
if (isset(TypeGuesser::DEPRECATED_TYPES[$type])) {
return $this->getTemplate(TypeGuesser::DEPRECATED_TYPES[$type]);
}

return null;
}

// NEXT_MAJOR: Remove the deprecation.
if (isset(TypeGuesser::DEPRECATED_TYPES[$type])) {
@trigger_error(sprintf(
'Overriding %s list template is deprecated since sonata-project/doctrine-orm-admin-bundle 3.19.'
.' You should override %s list template instead.',
$type,
TypeGuesser::DEPRECATED_TYPES[$type]
), E_USER_DEPRECATED);
}

return $this->templates[$type];
Expand Down
49 changes: 18 additions & 31 deletions src/Builder/ShowBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Sonata\AdminBundle\Builder\ShowBuilderInterface;
use Sonata\AdminBundle\Guesser\TypeGuesserInterface;
use Sonata\DoctrineORMAdminBundle\Guesser\TypeGuesser;

class ShowBuilder implements ShowBuilderInterface
{
Expand Down Expand Up @@ -89,35 +90,6 @@ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInter

if (!$fieldDescription->getTemplate()) {
$fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType()));

if (!$fieldDescription->getTemplate()) {
switch ($fieldDescription->getMappingType()) {
case ClassMetadata::MANY_TO_ONE:
$fieldDescription->setTemplate(
'@SonataAdmin/CRUD/Association/show_many_to_one.html.twig'
);

break;
case ClassMetadata::ONE_TO_ONE:
$fieldDescription->setTemplate(
'@SonataAdmin/CRUD/Association/show_one_to_one.html.twig'
);

break;
case ClassMetadata::ONE_TO_MANY:
$fieldDescription->setTemplate(
'@SonataAdmin/CRUD/Association/show_one_to_many.html.twig'
);

break;
case ClassMetadata::MANY_TO_MANY:
$fieldDescription->setTemplate(
'@SonataAdmin/CRUD/Association/show_many_to_many.html.twig'
);

break;
}
}
}

switch ($fieldDescription->getMappingType()) {
Expand All @@ -134,12 +106,27 @@ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInter
/**
* @param string $type
*
* @return string
* @return string|null
*/
private function getTemplate($type)
{
if (!isset($this->templates[$type])) {
return;
// NEXT_MAJOR: Remove the check for deprecated type and always return null.
if (isset(TypeGuesser::DEPRECATED_TYPES[$type])) {
return $this->getTemplate(TypeGuesser::DEPRECATED_TYPES[$type]);
}

return null;
}

// NEXT_MAJOR: Remove the deprecation.
if (isset(TypeGuesser::DEPRECATED_TYPES[$type])) {
@trigger_error(sprintf(
'Overriding %s show template is deprecated since sonata-project/doctrine-orm-admin-bundle 3.19.'
.' You should override %s show template instead.',
$type,
TypeGuesser::DEPRECATED_TYPES[$type]
), E_USER_DEPRECATED);
}

return $this->templates[$type];
Expand Down
29 changes: 21 additions & 8 deletions src/Filter/StringFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@

use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Form\Type\Filter\ChoiceType;
use Sonata\AdminBundle\Form\Type\Operator\ContainsOperatorType;
use Sonata\AdminBundle\Form\Type\Operator\StringOperatorType;

class StringFilter extends Filter
{
public const CHOICES = [
ContainsOperatorType::TYPE_CONTAINS => 'LIKE',
ContainsOperatorType::TYPE_NOT_CONTAINS => 'NOT LIKE',
ContainsOperatorType::TYPE_EQUAL => '=',
StringOperatorType::TYPE_CONTAINS => 'LIKE',
StringOperatorType::TYPE_STARTS_WITH => 'LIKE',
StringOperatorType::TYPE_ENDS_WITH => 'LIKE',
StringOperatorType::TYPE_NOT_CONTAINS => 'NOT LIKE',
StringOperatorType::TYPE_EQUAL => '=',
];

public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data): void
Expand All @@ -37,7 +39,7 @@ public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data)
return;
}

$data['type'] = !isset($data['type']) ? ContainsOperatorType::TYPE_CONTAINS : $data['type'];
$data['type'] = !isset($data['type']) ? StringOperatorType::TYPE_CONTAINS : $data['type'];

$operator = $this->getOperator((int) $data['type']);

Expand All @@ -56,22 +58,33 @@ public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data)
$or->add(sprintf('LOWER(%s.%s) %s :%s', $alias, $field, $operator, $parameterName));
}

if (ContainsOperatorType::TYPE_NOT_CONTAINS === $data['type']) {
if (StringOperatorType::TYPE_NOT_CONTAINS === $data['type']) {
$or->add($queryBuilder->expr()->isNull(sprintf('%s.%s', $alias, $field)));
}

$this->applyWhere($queryBuilder, $or);

if (ContainsOperatorType::TYPE_EQUAL === $data['type']) {
if (StringOperatorType::TYPE_EQUAL === $data['type']) {
$queryBuilder->setParameter(
$parameterName,
$this->getOption('case_sensitive') ? $data['value'] : mb_strtolower($data['value'])
);
} else {
switch ($data['type']) {
case StringOperatorType::TYPE_STARTS_WITH:
$format = '%s%%';
break;
case StringOperatorType::TYPE_ENDS_WITH:
$format = '%%%s';
break;
default:
$format = $this->getOption('format');
}

$queryBuilder->setParameter(
$parameterName,
sprintf(
$this->getOption('format'),
$format,
$this->getOption('case_sensitive') ? $data['value'] : mb_strtolower($data['value'])
)
);
Expand Down
1 change: 1 addition & 0 deletions src/Guesser/FilterTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class FilterTypeGuesser extends AbstractTypeGuesser
public function guessType($class, $property, ModelManagerInterface $modelManager)
{
if (!$ret = $this->getParentMetadataForProperty($class, $property, $modelManager)) {
// NEXT_MAJOR: Return null.
return false;
}

Expand Down
Loading

0 comments on commit 4386d7d

Please sign in to comment.