Skip to content

Commit 0b40429

Browse files
committed
Upgrade EasyAdmin to 4.29
1 parent 0e95d2a commit 0b40429

20 files changed

Lines changed: 892 additions & 1906 deletions

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Docker commands
2+
.PHONY: node-modules-install
3+
node-modules-install:
4+
docker compose run --rm --user 1000:1000 node yarn install --frozen-lockfile
5+
26
.PHONY: build-assets
37
build-assets:
48
docker compose run --rm --user 1000:1000 node yarn build

assets/js/app.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1 @@
11
import '../css/app.css';
2-
3-
import ConfirmationModal from './confirmation-modal';
4-
5-
document.addEventListener('DOMContentLoaded', () => {
6-
App.createConfirmationActionModal();
7-
});
8-
9-
const App = (() => {
10-
const createConfirmationActionModal = () => {
11-
const confirmationModal = new ConfirmationModal();
12-
document.querySelectorAll("[data-protung-easyadmin-plus-extension-modal-confirm-trigger='1']").forEach((action) => {
13-
confirmationModal.create(action);
14-
});
15-
};
16-
17-
return {
18-
createConfirmationActionModal: createConfirmationActionModal,
19-
};
20-
})();

assets/js/confirmation-modal.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"php": "~8.4.0 || ~8.5.0",
2828
"ext-dom": "*",
2929
"azjezz/psl": "^2.9.1 || ^3.0.0 || ^4.0.0",
30-
"easycorp/easyadmin-bundle": "~4.27.7",
30+
"easycorp/easyadmin-bundle": "~4.29.1",
3131
"symfony/asset": "^6.4 || ^7.4",
3232
"symfony/cache": "^6.4 || ^7.4",
3333
"symfony/config": "^6.4 || ^7.4",

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"devDependencies": {
3-
"@babel/core": "^7.28.5",
4-
"@babel/preset-env": "^7.28.5",
3+
"@babel/core": "^7.29.0",
4+
"@babel/preset-env": "^7.29.0",
55
"@popperjs/core": "^2.11.8",
66
"@symfony/webpack-encore": "^5.3.1",
7-
"webpack": "^5.103.0",
7+
"webpack": "^5.105.3",
88
"webpack-cli": "^6.0.1"
99
},
1010
"license": "MIT",

src/Controller/BaseController.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Protung\EasyAdminPlusBundle\Controller;
66

7+
use EasyCorp\Bundle\EasyAdminBundle\Twig\Component\Option\AlertVariant;
78
use Override;
89
use Psl\Dict;
910
use Stringable;
@@ -17,20 +18,20 @@ abstract class BaseController extends AbstractController
1718
{
1819
protected function addFlashMessageSuccess(string|Stringable|TranslatableInterface $message): void
1920
{
20-
$this->addFlashMessage(Flash::Success, $message);
21+
$this->addFlashMessage(AlertVariant::Success, $message);
2122
}
2223

2324
protected function addFlashMessageWarning(string|Stringable|TranslatableInterface $message): void
2425
{
25-
$this->addFlashMessage(Flash::Warning, $message);
26+
$this->addFlashMessage(AlertVariant::Warning, $message);
2627
}
2728

2829
protected function addFlashMessageError(string|Stringable|TranslatableInterface $message): void
2930
{
30-
$this->addFlashMessage(Flash::Error, $message);
31+
$this->addFlashMessage(AlertVariant::Error, $message);
3132
}
3233

33-
protected function addFlashMessage(Flash $type, string|Stringable|TranslatableInterface $message): void
34+
protected function addFlashMessage(AlertVariant $type, string|Stringable|TranslatableInterface $message): void
3435
{
3536
// We check against TranslatableInterface because the implementation might be Stringable as well.
3637
if (! $message instanceof TranslatableInterface) {

src/Controller/BaseCrudController.php

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use EasyCorp\Bundle\EasyAdminBundle\Dto\ActionDto;
1212
use EasyCorp\Bundle\EasyAdminBundle\Dto\ActionGroupDto;
1313
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
14+
use EasyCorp\Bundle\EasyAdminBundle\Twig\Component\Option\AlertVariant;
1415
use Override;
1516
use Psl\Dict;
1617
use Psl\Iter;
@@ -29,9 +30,6 @@
2930
*/
3031
abstract class BaseCrudController extends AbstractCrudController
3132
{
32-
protected const string FIELD_SORT_ASC = 'ASC';
33-
protected const string FIELD_SORT_DESC = 'DESC';
34-
3533
/**
3634
* Calling this method will disable all standard actions.
3735
*/
@@ -97,24 +95,6 @@ final protected function applyToAllActions(Actions $actions, callable $apply): A
9795
return $actions;
9896
}
9997

100-
protected function addConfirmationForAction(
101-
Action $action,
102-
string|Stringable|TranslatableInterface $title,
103-
string|Stringable|TranslatableInterface $description,
104-
): Action {
105-
$action
106-
->getAsDto()
107-
->addHtmlAttributes(
108-
[
109-
'data-protung-easyadmin-plus-extension-modal-confirm-trigger' => '1',
110-
'data-protung-easyadmin-plus-extension-modal-confirm-title' => $this->translate($title),
111-
'data-protung-easyadmin-plus-extension-modal-confirm-description' => $this->translate($description),
112-
],
113-
);
114-
115-
return $action;
116-
}
117-
11898
/**
11999
* @return AdminContext<TEntity>
120100
*/
@@ -130,20 +110,20 @@ protected function currentAdminContext(): AdminContext
130110

131111
protected function addFlashMessageSuccess(string|Stringable|TranslatableInterface $message): void
132112
{
133-
$this->addFlashMessage(Flash::Success, $message);
113+
$this->addFlashMessage(AlertVariant::Success, $message);
134114
}
135115

136116
protected function addFlashMessageWarning(string|Stringable|TranslatableInterface $message): void
137117
{
138-
$this->addFlashMessage(Flash::Warning, $message);
118+
$this->addFlashMessage(AlertVariant::Warning, $message);
139119
}
140120

141121
protected function addFlashMessageError(string|Stringable|TranslatableInterface $message): void
142122
{
143-
$this->addFlashMessage(Flash::Error, $message);
123+
$this->addFlashMessage(AlertVariant::Error, $message);
144124
}
145125

146-
protected function addFlashMessage(Flash $type, string|Stringable|TranslatableInterface $message): void
126+
protected function addFlashMessage(AlertVariant $type, string|Stringable|TranslatableInterface $message): void
147127
{
148128
$this->addFlash($type->value, $this->translate($message));
149129
}

src/Controller/BaseCrudDtoController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function edit(AdminContext $context): KeyValueStore|Response
115115
throw new InsufficientEntityPermissionException($context);
116116
}
117117

118-
$this->container->get(FieldFactory::class)->processFields($context->getEntity(), FieldCollection::new($this->configureFields(Crud::PAGE_EDIT)), Crud::PAGE_EDIT);
118+
$this->container->get(FieldFactory::class)->processFields($context->getEntity(), new FieldCollection($this->configureFields(Crud::PAGE_EDIT)), Crud::PAGE_EDIT);
119119
$context->getCrud()->setFieldAssets($this->getFieldAssets($context->getEntity()->getFields()));
120120
$this->container->get(ActionFactory::class)->processEntityActions($context->getEntity(), $context->getCrud()->getActionsConfig());
121121
/** @var TDto $dto */
@@ -129,9 +129,9 @@ public function edit(AdminContext $context): KeyValueStore|Response
129129
if (!$this->isCsrfTokenValid(BooleanField::CSRF_TOKEN_NAME, $context->getRequest()->query->get('csrfToken'))) {
130130
if (class_exists(InvalidCsrfTokenException::class)) {
131131
throw new InvalidCsrfTokenException();
132-
} else {
133-
return new Response('Invalid CSRF token.', 400);
134132
}
133+
134+
return new Response('Invalid CSRF token.', 400);
135135
}
136136

137137
$fieldName = $context->getRequest()->query->get('fieldName');
@@ -218,7 +218,7 @@ public function new(AdminContext $context): KeyValueStore|Response
218218

219219
$context->getEntity()->setInstance(null);
220220
$context->getEntity()->setInstance($this->createDto());
221-
$this->container->get(FieldFactory::class)->processFields($context->getEntity(), FieldCollection::new($this->configureFields(Crud::PAGE_NEW)), Crud::PAGE_NEW);
221+
$this->container->get(FieldFactory::class)->processFields($context->getEntity(), new FieldCollection($this->configureFields(Crud::PAGE_NEW)), Crud::PAGE_NEW);
222222
$context->getCrud()->setFieldAssets($this->getFieldAssets($context->getEntity()->getFields()));
223223
$this->container->get(ActionFactory::class)->processEntityActions($context->getEntity(), $context->getCrud()->getActionsConfig());
224224

src/Controller/Flash.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/Field/Configurator/EntityConfigurator.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c
7272

7373
$sourceCrudControllerFqcn = Type\class_string(CrudControllerInterface::class)->coerce($crud->getControllerFqcn());
7474

75-
$targetEntityFqcn = Type\string()->coerce($context->getCrudControllers()->findEntityFqcnByCrudFqcn($targetCrudControllerFqcn));
75+
$targetEntityFqcn = Type\string()->coerce($context->getAdminControllers()->findEntityByCrudController($targetCrudControllerFqcn));
7676
invariant(Class\exists($targetEntityFqcn), 'Could not determine target entity for set CRUD controller.');
7777
invariant(Class\exists($targetCrudControllerFqcn), 'Could not determine target CRUD controller.');
7878

@@ -106,6 +106,10 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c
106106
$widgetMode = Type\string()->coerce($field->getCustomOption(EntityField::OPTION_WIDGET));
107107
if ($widgetMode === EntityField::WIDGET_AUTOCOMPLETE) {
108108
$field->setFormTypeOption('attr.data-ea-widget', 'ea-autocomplete');
109+
110+
// both autocomplete(renderAsHtml: true) and renderAsHtml(true) set the same option.
111+
// OPTION_ESCAPE_HTML_CONTENTS has inverted logic (true = escape, false = render as HTML)
112+
$field->setFormTypeOption('attr.data-ea-autocomplete-render-items-as-html', $field->getCustomOption(EntityField::OPTION_ESCAPE_HTML_CONTENTS) === true ? 'false' : 'true');
109113
} elseif ($widgetMode === EntityField::WIDGET_NATIVE) {
110114
$field->setFormTypeOption('class', $entityMetadata->targetEntityFqcn());
111115
}
@@ -134,14 +138,16 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c
134138
} else {
135139
$field->setFormTypeOptionIfNotSet('query_builder', static function (EntityRepository $repository) use ($field): QueryBuilder {
136140
// it would then be identical to the one used in autocomplete action, but it is a bit complex getting it in here
137-
$queryBuilder = $repository->createQueryBuilder('entity');
141+
$queryBuilder = $repository->createQueryBuilder('entity');
142+
/** @var (callable(QueryBuilder): QueryBuilder)|null $queryBuilderCallable */
138143
$queryBuilderCallable = $field->getCustomOption(EntityField::OPTION_QUERY_BUILDER_CALLABLE);
139144
if ($queryBuilderCallable !== null) {
140145
invariant(
141146
is_callable($queryBuilderCallable),
142147
Str\format('Query builder callable option is not null or callable.'),
143148
);
144-
$queryBuilderCallable($queryBuilder);
149+
150+
return $queryBuilderCallable($queryBuilder);
145151
}
146152

147153
return $queryBuilder;

0 commit comments

Comments
 (0)