Skip to content

Commit

Permalink
Merge branch '4.x' into 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Nov 15, 2024
2 parents 6ce7bf0 + 67b39f0 commit 029cd07
Show file tree
Hide file tree
Showing 146 changed files with 381 additions and 191 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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/).

## [4.32.0](https://github.com/sonata-project/SonataAdminBundle/compare/4.31.0...4.32.0) - 2024-11-14
### Added
- [[#8213](https://github.com/sonata-project/SonataAdminBundle/pull/8213)] Support for select2 tags option ([@micbis](https://github.com/micbis))

### Changed
- [[#8212](https://github.com/sonata-project/SonataAdminBundle/pull/8212)] Enums implementing Symfony's `TranslatableInterface` are now correctly translated by the `FieldDescriptionInterface::TYPE_ENUM` field type ([@zyberspace](https://github.com/zyberspace))

## [4.31.0](https://github.com/sonata-project/SonataAdminBundle/compare/4.30.2...4.31.0) - 2024-07-15
### Added
- [[#8192](https://github.com/sonata-project/SonataAdminBundle/pull/8192)] Enable security information mapping for `RoleSecurityHandler` ([@core23](https://github.com/core23))
Expand Down
6 changes: 6 additions & 0 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const Admin = {
const popover = select.data('popover');
let maximumSelectionLength = null;
let minimumResultsForSearch = 10;
let allowTags = false;

select.removeClass('form-control');

Expand All @@ -101,6 +102,10 @@ const Admin = {
allowClearEnabled = false;
}

if (select.attr('data-sonata-select2-allow-tags') === 'true') {
allowTags = true;
}

if (select.attr('data-sonata-select2-maximumSelectionLength')) {
maximumSelectionLength = select.attr('data-sonata-select2-maximumSelectionLength');
}
Expand All @@ -117,6 +122,7 @@ const Admin = {
placeholder: allowClearEnabled ? ' ' : '', // allowClear needs placeholder to work properly
allowClear: allowClearEnabled,
maximumSelectionLength,
tags: allowTags,
});

if (undefined !== popover) {
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"matthiasnoback/symfony-config-test": "^4.2 || ^5.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.2 || ^5.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpdoc-parser": "^1.0",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
Expand Down
23 changes: 23 additions & 0 deletions docs/cookbook/recipe_select2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ to enable ``allowClear`` or ``data-sonata-select2-allow-clear = "false"`` to dis

You have to use false as string! ``"false"``!

AllowTags
----------

Select2 parameter ``allowTags`` can be set using the data attribute ``data-sonata-select2-allow-tags="true"``
to enable ``allowTags``::

use Sonata\AdminBundle\Form\Type\ModelType;

protected function configureFormFields(FormMapper $form): void
{
$form
->add('category', ModelType::class, [
'attr' => [
'data-sonata-select2-allow-tags' => 'true'
]
])
;
}

.. note::

You have to use true as string! ``"true"``!

Minimum results for search
--------------------------

Expand Down
58 changes: 53 additions & 5 deletions docs/reference/field_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Fieldtype Description
``FieldDescriptionInterface::TYPE_DATETIME`` display a formatted date and time. Accepts the options ``format`` and ``timezone``
``FieldDescriptionInterface::TYPE_STRING`` display a text
``FieldDescriptionInterface::TYPE_EMAIL`` display a mailto link. Accepts the options ``as_string``, ``subject`` and ``body``
``FieldDescriptionInterface::TYPE_ENUM`` display the name of a backed enum
``FieldDescriptionInterface::TYPE_ENUM`` display an enum
``FieldDescriptionInterface::TYPE_TEXTAREA`` display a textarea
``FieldDescriptionInterface::TYPE_TRANS`` translate the value with a provided ``value_translation_domain`` and ``format`` (sprintf format) option
``FieldDescriptionInterface::TYPE_FLOAT`` display a number
Expand Down Expand Up @@ -199,13 +199,61 @@ The ``FieldDescriptionInterface::TYPE_CHOICE`` field type also supports multiple

You can use the following options:

====================================== ==============================================================
====================================== ========================================================================
Option Description
====================================== ==============================================================
====================================== ========================================================================
**use_value** Determines if the field must show the value or the case' name.
``false`` by default.
**enum_translation_domain** Translation domain.
====================================== ==============================================================

*Ignored if the enum implements Symfony's* ``TranslatableInterface`` *.*
**enum_translation_domain** | Translation domain. If set, the enum value or case' name will be send
to the translator.
| ``{{ value|trans({}, translation_domain) }}``

*Ignored if the enum implements Symfony's* ``TranslatableInterface`` *.*
====================================== ========================================================================

.. note::

If the enum implements Symfony's ``TranslatableInterface`` the options above will be ignored and the enum's
``trans()`` method will be used instead to display the enum.

This provides full compatibility with symfony's
`EnumType <https://symfony.com/doc/current/reference/forms/types/enum.html>`_ form type:

::

protected function configureListFields(ListMapper $list): void
{
$list
// Sonata Admin will select the `FieldDescriptionInterface::TYPE_ENUM`
// field type automatically. If the enum implements `TranslatableInterface`,
// the `trans()` method will be used to render its value.
->add('saluation')
;
}

protected function configureFormFields(FormMapper $form): void
{
$form
// Symfony's EnumType form field will automatically detect the usage of
// the `TranslatableInterface` and use the enum's `trans()` method to
// render the choice labels.
->add('salutation', EnumType::class, [
'class' => Salutation::class,
])
;
}

protected function configureShowFields(ShowMapper $show): void
{
$show
// Again, Sonata Admin will select the `FieldDescriptionInterface::TYPE_ENUM`
// field type automatically. If the enum implements `TranslatableInterface`,
// the `trans()` method will be used to render its value.
->add('salutation')
;
}

``FieldDescriptionInterface::TYPE_URL``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use Rector\Config\RectorConfig;
use Rector\Php70\Rector\FunctionLike\ExceptionHandlerTypehintRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\NarrowUnusedSetUpDefinedPropertyRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
Expand All @@ -40,5 +41,6 @@
$rectorConfig->skip([
ExceptionHandlerTypehintRector::class,
PreferPHPUnitThisCallRector::class,
NarrowUnusedSetUpDefinedPropertyRector::class,
]);
};
2 changes: 1 addition & 1 deletion src/Action/AppendFormFieldElementAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class AppendFormFieldElementAction
public function __construct(
private Environment $twig,
private AdminFetcherInterface $adminFetcher,
private AdminHelper $helper
private AdminHelper $helper,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Action/DashboardAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class DashboardAction
public function __construct(
private array $dashboardBlocks,
private TemplateRegistryInterface $templateRegistry,
private Environment $twig
private Environment $twig,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Action/GetShortObjectDescriptionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class GetShortObjectDescriptionAction
{
public function __construct(
private Environment $twig,
private AdminFetcherInterface $adminFetcher
private AdminFetcherInterface $adminFetcher,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Action/RetrieveAutocompleteItemsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
final class RetrieveAutocompleteItemsAction
{
public function __construct(
private AdminFetcherInterface $adminFetcher
private AdminFetcherInterface $adminFetcher,
) {
}

Expand Down Expand Up @@ -232,7 +232,7 @@ public function __invoke(Request $request): JsonResponse
*/
private function retrieveFilterFieldDescription(
AdminInterface $admin,
string $field
string $field,
): FieldDescriptionInterface {
if (!$admin->hasFilterFieldDescription($field)) {
throw new \RuntimeException(\sprintf('The field "%s" does not exist.', $field));
Expand All @@ -256,7 +256,7 @@ private function retrieveFilterFieldDescription(
*/
private function retrieveFormFieldDescription(
AdminInterface $admin,
string $field
string $field,
): FieldDescriptionInterface {
if (!$admin->hasFormFieldDescription($field)) {
throw new \RuntimeException(\sprintf('The field "%s" does not exist.', $field));
Expand Down
2 changes: 1 addition & 1 deletion src/Action/RetrieveFormFieldElementAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class RetrieveFormFieldElementAction
public function __construct(
private Environment $twig,
private AdminFetcherInterface $adminFetcher,
private AdminHelper $helper
private AdminHelper $helper,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Action/SearchAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class SearchAction
public function __construct(
private Pool $pool,
private TemplateRegistryInterface $templateRegistry,
private Environment $twig
private Environment $twig,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Action/SetObjectFieldValueAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
private ValidatorInterface $validator,
private DataTransformerResolverInterface $resolver,
private PropertyAccessorInterface $propertyAccessor,
?RenderElementRuntime $renderElementRuntime = null
?RenderElementRuntime $renderElementRuntime = null,
) {
// NEXT_MAJOR: Remove the deprecation and restrict param constructor to RenderElementRuntime.
if (null === $renderElementRuntime) {
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ final public function isChild(): bool
/**
* Returns true if the admin has children, false otherwise.
*
* @phpstan-assert-if-true non-empty-array $this->children
* @phpstan-assert-if-true non-empty-array<string, AdminInterface<object>> $this->children
*/
final public function hasChildren(): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/AbstractAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function configureActionButtons(
AdminInterface $admin,
array $list,
string $action,
?object $object = null
?object $object = null,
): array {
return $list;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Admin/AdminExtensionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function configureTabMenu(
AdminInterface $admin,
MenuItemInterface $menu,
string $action,
?AdminInterface $childAdmin = null
?AdminInterface $childAdmin = null,
): void;

/**
Expand Down Expand Up @@ -200,7 +200,7 @@ public function configureActionButtons(
AdminInterface $admin,
array $list,
string $action,
?object $object = null
?object $object = null,
): array;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/AdminHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AdminHelper
private const FORM_FIELD_DELETE = '_delete';

public function __construct(
private PropertyAccessorInterface $propertyAccessor
private PropertyAccessorInterface $propertyAccessor,
) {
}

Expand Down
2 changes: 2 additions & 0 deletions src/Admin/AdminInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
* @method bool showInDashboard()
* @method void removeExtension(AdminExtensionInterface $extension)
*
* @phpstan-method void removeExtension(AdminExtensionInterface<T> $extension)
*
* @phpstan-import-type FieldDescriptionOptions from FieldDescriptionInterface
*
* @phpstan-template T of object
Expand Down
4 changes: 2 additions & 2 deletions src/Admin/BreadcrumbsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function getBreadcrumbs(AdminInterface $admin, string $action): array
public function buildBreadcrumbs(
AdminInterface $admin,
string $action,
?ItemInterface $menu = null
?ItemInterface $menu = null,
): ItemInterface {
if (null === $menu) {
$menu = $admin->getMenuFactory()->createItem('root');
Expand Down Expand Up @@ -161,7 +161,7 @@ private function createMenuItem(
ItemInterface $menu,
string $name,
?string $translationDomain = null,
array $options = []
array $options = [],
): ItemInterface {
$options = array_merge([
'extras' => [
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct(
private ContainerInterface $container,
private array $adminServiceCodes = [],
private array $adminGroups = [],
private array $adminClasses = []
private array $adminClasses = [],
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Admin/UrlGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function generateObjectUrl(
string $name,
object $object,
array $parameters = [],
int $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH
int $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH,
): string;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ArgumentResolver/AdminValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
final class AdminValueResolver implements CompatibleValueResolverInterface
{
public function __construct(
private AdminFetcherInterface $adminFetcher
private AdminFetcherInterface $adminFetcher,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Block/AdminListBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class AdminListBlockService extends AbstractBlockService
public function __construct(
Environment $twig,
private Pool $pool,
private TemplateRegistryInterface $templateRegistry
private TemplateRegistryInterface $templateRegistry,
) {
parent::__construct($twig);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Block/AdminPreviewBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class AdminPreviewBlockService extends AbstractBlockService
{
public function __construct(
Environment $twig,
private Pool $pool
private Pool $pool,
) {
parent::__construct($twig);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Block/AdminSearchBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(
private SearchHandlerInterface $searchHandler,
private TemplateRegistryInterface $templateRegistry,
private string $emptyBoxesOption,
private string $adminRoute
private string $adminRoute,
) {
parent::__construct($twig);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Block/AdminStatsBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class AdminStatsBlockService extends AbstractBlockService
{
public function __construct(
Environment $twig,
private Pool $pool
private Pool $pool,
) {
parent::__construct($twig);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Exporter/AdminExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
final class AdminExporter
{
public function __construct(
private ExporterInterface $exporter
private ExporterInterface $exporter,
) {
}

Expand Down
Loading

0 comments on commit 029cd07

Please sign in to comment.