Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Docker commands
.PHONY: node-modules-install
node-modules-install:
docker compose run --rm --user 1000:1000 node yarn install --frozen-lockfile

.PHONY: build-assets
build-assets:
docker compose run --rm --user 1000:1000 node yarn build
Expand Down
19 changes: 0 additions & 19 deletions assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
import '../css/app.css';

import ConfirmationModal from './confirmation-modal';

document.addEventListener('DOMContentLoaded', () => {
App.createConfirmationActionModal();
});

const App = (() => {
const createConfirmationActionModal = () => {
const confirmationModal = new ConfirmationModal();
document.querySelectorAll("[data-protung-easyadmin-plus-extension-modal-confirm-trigger='1']").forEach((action) => {
confirmationModal.create(action);
});
};

return {
createConfirmationActionModal: createConfirmationActionModal,
};
})();
39 changes: 0 additions & 39 deletions assets/js/confirmation-modal.js

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"php": "~8.4.0 || ~8.5.0",
"ext-dom": "*",
"azjezz/psl": "^2.9.1 || ^3.0.0 || ^4.0.0",
"easycorp/easyadmin-bundle": "~4.27.7",
"easycorp/easyadmin-bundle": "~4.29.1",
"symfony/asset": "^6.4 || ^7.4",
"symfony/cache": "^6.4 || ^7.4",
"symfony/config": "^6.4 || ^7.4",
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"devDependencies": {
"@babel/core": "^7.28.5",
"@babel/preset-env": "^7.28.5",
"@babel/core": "^7.29.0",
"@babel/preset-env": "^7.29.0",
"@popperjs/core": "^2.11.8",
"@symfony/webpack-encore": "^5.3.1",
"webpack": "^5.103.0",
"webpack": "^5.105.3",
"webpack-cli": "^6.0.1"
},
"license": "MIT",
Expand Down
64 changes: 12 additions & 52 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="6.14.3@d0b040a91f280f071c1abcb1b77ce3822058725a">
<files psalm-version="6.15.1@28dc127af1b5aecd52314f6f645bafc10d0e11f9">
<file src="src/Controller/BaseCrudController.php">
<ArgumentTypeCoercion>
<code><![CDATA[$apply]]></code>
Expand Down Expand Up @@ -84,6 +84,9 @@
<code><![CDATA[$entityDto->getPrimaryKeyValue()]]></code>
<code><![CDATA[$field->getValue()]]></code>
</MixedArgument>
<RedundantConditionGivenDocblockType>
<code><![CDATA[invariant]]></code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Form/DataTransformer/EntityFieldDataTransformer.php">
<MissingTemplateParam>
Expand All @@ -108,57 +111,14 @@
<code><![CDATA[$menuItemQueryString]]></code>
</PossiblyFalseArgument>
</file>
<file src="src/Orm/EntityRepository.php">
<ArgumentTypeCoercion>
<code><![CDATA[$targetCrudControllerFqcn]]></code>
</ArgumentTypeCoercion>
<InvalidArrayAccess>
<code><![CDATA[$fieldMapping['type']]]></code>
<code><![CDATA[$fieldMapping['type']]]></code>
</InvalidArrayAccess>
<InvalidOperand>
<code><![CDATA[0 + $queryTerm]]></code>
</InvalidOperand>
<MixedArgument>
<code><![CDATA[$entityDto->getClassMetadata()->getAssociationMapping($sortProperty)['mappedBy']]]></code>
<code><![CDATA[$entityFqcn]]></code>
<code><![CDATA[$idClassName]]></code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code><![CDATA[$submittedData]]></code>
</MixedArgumentTypeCoercion>
<MixedMethodCall>
<code><![CDATA[getFqcn]]></code>
</MixedMethodCall>
<MixedOperand>
<code><![CDATA[$associationSortProperty]]></code>
</MixedOperand>
<MixedReturnTypeCoercion>
<code><![CDATA[$searchablePropertiesConfig]]></code>
<code><![CDATA[array<array{
* entity_name: string,
* property_data_type: string,
* property_name: string,
* is_boolean: bool,
* is_small_integer: bool,
* is_integer: bool,
* is_numeric: bool,
* is_text: bool,
* is_guid: bool,
* is_ulid: bool,
* is_json: bool,
* }>]]></code>
</MixedReturnTypeCoercion>
<PossiblyNullReference>
<code><![CDATA[getRequest]]></code>
</PossiblyNullReference>
<PossiblyUndefinedMethod>
<code><![CDATA[getName]]></code>
</PossiblyUndefinedMethod>
<TypeDoesNotContainType>
<code><![CDATA[is_array($fieldMapping)]]></code>
<code><![CDATA[is_array($fieldMapping)]]></code>
</TypeDoesNotContainType>
<file src="src/Orm/EntityPaginator.php">
<TooManyArguments>
<code><![CDATA[getResultsAsJson]]></code>
<code><![CDATA[getResultsAsJson]]></code>
<code><![CDATA[getResultsAsJson]]></code>
<code><![CDATA[getResultsAsJson]]></code>
<code><![CDATA[getResultsAsJson]]></code>
</TooManyArguments>
</file>
<file src="src/Test/Controller/AdminControllerWebTestCase.php">
<InvalidArgument>
Expand Down
9 changes: 5 additions & 4 deletions src/Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Protung\EasyAdminPlusBundle\Controller;

use EasyCorp\Bundle\EasyAdminBundle\Twig\Component\Option\AlertVariant;
use Override;
use Psl\Dict;
use Stringable;
Expand All @@ -17,20 +18,20 @@ abstract class BaseController extends AbstractController
{
protected function addFlashMessageSuccess(string|Stringable|TranslatableInterface $message): void
{
$this->addFlashMessage(Flash::Success, $message);
$this->addFlashMessage(AlertVariant::Success, $message);
}

protected function addFlashMessageWarning(string|Stringable|TranslatableInterface $message): void
{
$this->addFlashMessage(Flash::Warning, $message);
$this->addFlashMessage(AlertVariant::Warning, $message);
}

protected function addFlashMessageError(string|Stringable|TranslatableInterface $message): void
{
$this->addFlashMessage(Flash::Error, $message);
$this->addFlashMessage(AlertVariant::Error, $message);
}

protected function addFlashMessage(Flash $type, string|Stringable|TranslatableInterface $message): void
protected function addFlashMessage(AlertVariant $type, string|Stringable|TranslatableInterface $message): void
{
// We check against TranslatableInterface because the implementation might be Stringable as well.
if (! $message instanceof TranslatableInterface) {
Expand Down
30 changes: 5 additions & 25 deletions src/Controller/BaseCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Dto\ActionDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\ActionGroupDto;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Twig\Component\Option\AlertVariant;
use Override;
use Psl\Dict;
use Psl\Iter;
Expand All @@ -29,9 +30,6 @@
*/
abstract class BaseCrudController extends AbstractCrudController
{
protected const string FIELD_SORT_ASC = 'ASC';
protected const string FIELD_SORT_DESC = 'DESC';

/**
* Calling this method will disable all standard actions.
*/
Expand Down Expand Up @@ -97,24 +95,6 @@ final protected function applyToAllActions(Actions $actions, callable $apply): A
return $actions;
}

protected function addConfirmationForAction(
Action $action,
string|Stringable|TranslatableInterface $title,
string|Stringable|TranslatableInterface $description,
): Action {
$action
->getAsDto()
->addHtmlAttributes(
[
'data-protung-easyadmin-plus-extension-modal-confirm-trigger' => '1',
'data-protung-easyadmin-plus-extension-modal-confirm-title' => $this->translate($title),
'data-protung-easyadmin-plus-extension-modal-confirm-description' => $this->translate($description),
],
);

return $action;
}

/**
* @return AdminContext<TEntity>
*/
Expand All @@ -130,20 +110,20 @@ protected function currentAdminContext(): AdminContext

protected function addFlashMessageSuccess(string|Stringable|TranslatableInterface $message): void
{
$this->addFlashMessage(Flash::Success, $message);
$this->addFlashMessage(AlertVariant::Success, $message);
}

protected function addFlashMessageWarning(string|Stringable|TranslatableInterface $message): void
{
$this->addFlashMessage(Flash::Warning, $message);
$this->addFlashMessage(AlertVariant::Warning, $message);
}

protected function addFlashMessageError(string|Stringable|TranslatableInterface $message): void
{
$this->addFlashMessage(Flash::Error, $message);
$this->addFlashMessage(AlertVariant::Error, $message);
}

protected function addFlashMessage(Flash $type, string|Stringable|TranslatableInterface $message): void
protected function addFlashMessage(AlertVariant $type, string|Stringable|TranslatableInterface $message): void
{
$this->addFlash($type->value, $this->translate($message));
}
Expand Down
8 changes: 4 additions & 4 deletions src/Controller/BaseCrudDtoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function edit(AdminContext $context): KeyValueStore|Response
throw new InsufficientEntityPermissionException($context);
}

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

return new Response('Invalid CSRF token.', 400);
}

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

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

Expand Down
16 changes: 0 additions & 16 deletions src/Controller/Flash.php

This file was deleted.

19 changes: 18 additions & 1 deletion src/Field/AdvancedDisplayField.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

use function htmlspecialchars;
use function is_callable;

use const ENT_QUOTES;
use const ENT_SUBSTITUTE;

trait AdvancedDisplayField
{
public const string OPTION_ENTITY_DISPLAY_FIELD = 'entityDisplayField';
Expand Down Expand Up @@ -46,7 +51,7 @@ public static function getEntityDisplayField(FieldDto $field): string|callable|n
return Type\nullable(Type\string())->coerce($value);
}

public static function formatAsString(object|null $entityInstance, FieldDto $field, TranslatorInterface $translator): string|null
public static function formatAsString(object|null $entityInstance, FieldDto $field, TranslatorInterface $translator, Environment $twig): string|null
{
if ($entityInstance === null) {
return null;
Expand All @@ -67,6 +72,18 @@ public static function formatAsString(object|null $entityInstance, FieldDto $fie
return (string) $entityInstance;
}

// This is only for autocomplete fields.
$twigTemplate = $field->getCustomOption(EntityField::OPTION_AUTOCOMPLETE_TEMPLATE);
if ($twigTemplate !== null) {
$renderAsHtml = $field->getCustomOption(EntityField::OPTION_ESCAPE_HTML_CONTENTS) === false;
$entityAsString = $twig->render(Type\string()->coerce($twigTemplate), ['entity' => $entityInstance]);
if (! $renderAsHtml) {
$entityAsString = htmlspecialchars($entityAsString, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}

return $entityAsString;
}

throw new RuntimeException(
Str\format(
'The "%s" field cannot be configured because it does not define the related entity display value set with the "setEntityDisplayField()" method. or implement "__toString()".',
Expand Down
Loading