Skip to content

Commit

Permalink
Fix assets not loaded for fields generated automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Jul 10, 2024
1 parent 5f4413d commit 29775b9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Collection/EntityCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public function set(EntityDto $newOrUpdatedEntity): void
$this->entities[$newOrUpdatedEntity->getPrimaryKeyValueAsString()] = $newOrUpdatedEntity;
}

public function first(): ?EntityDto
{
return $this->entities[array_key_first($this->entities)] ?? null;
}

public function offsetExists(mixed $offset): bool
{
return \array_key_exists($offset, $this->entities);
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/AbstractCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public function index(AdminContext $context)
}

$fields = FieldCollection::new($this->configureFields(Crud::PAGE_INDEX));
$context->getCrud()->setFieldAssets($this->getFieldAssets($fields));
$filters = $this->container->get(FilterFactory::class)->create($context->getCrud()->getFiltersConfig(), $fields, $context->getEntity());
$queryBuilder = $this->createIndexQueryBuilder($context->getSearch(), $context->getEntity(), $fields, $filters);
$paginator = $this->container->get(PaginatorFactory::class)->create($queryBuilder);
Expand All @@ -142,6 +141,8 @@ public function index(AdminContext $context)

$entities = $this->container->get(EntityFactory::class)->createCollection($context->getEntity(), $paginator->getResults());
$this->container->get(EntityFactory::class)->processFieldsForAll($entities, $fields);
$procesedFields = $entities->first()?->getFields() ?? FieldCollection::new([]);
$context->getCrud()->setFieldAssets($this->getFieldAssets($procesedFields));
$actions = $this->container->get(EntityFactory::class)->processActionsForAll($entities, $context->getCrud()->getActionsConfig());

$responseParameters = $this->configureResponseParameters(KeyValueStore::new([
Expand Down
2 changes: 1 addition & 1 deletion src/Orm/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private function getSearchablePropertiesConfig(QueryBuilder $queryBuilder, Searc
$associatedEntityAlias = $associatedPropertyName = '';
for ($i = 0; $i < $numAssociatedProperties - 1; ++$i) {
$associatedEntityName = $associatedProperties[$i];
$associatedEntityAlias = Escaper::escapeDqlAlias($associatedEntityName).($i ?: '');
$associatedEntityAlias = Escaper::escapeDqlAlias($associatedEntityName).((string) $i);

This comment has been minimized.

Copy link
@zorn-v

zorn-v Jul 21, 2024

Contributor

It is not correct fix. Before "0" is not appended.
Now it generate exeption like

[Semantical Error] line 0, col 354 near '.field field1': Error: Identification Variable sub_entity used in join path expression but was not defined before.

5f4413d#commitcomment-144328672

This comment has been minimized.

Copy link
@astronati

astronati Jul 26, 2024

This is causing an error!

@javiereguiluz
If you see #6387 it seems this change is the root cause of the problem

This comment has been minimized.

Copy link
@ksn135

ksn135 Jul 26, 2024

Contributor

Correct code should be:

$associatedEntityAlias = Escaper::escapeDqlAlias($associatedEntityName) . ((string)($i ?: ''));

I'll make a patch

This comment has been minimized.

Copy link
@ksn135

ksn135 Jul 26, 2024

Contributor

see PR #6388

$associatedPropertyName = $associatedProperties[$i + 1];

if (!\in_array($associatedEntityAlias, $entitiesAlreadyJoined, true)) {
Expand Down

0 comments on commit 29775b9

Please sign in to comment.