-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] [RFC] Embedded crud in forms #6384
base: 4.x
Are you sure you want to change the base?
Conversation
fd78221
to
f379763
Compare
@psihius can you please share a screenshot of how i looks like when we embed a data table in a form? |
|
/** @var array|null $embedContext */ | ||
$embedContext = $context->getRequest()->query->all('embedContext'); | ||
if (\array_key_exists('mappedBy', $embedContext)) { | ||
$filterProperty = $embedContext['mappedBy']; | ||
$filterValue = $embedContext['embeddedIn'] ?? null; | ||
if (null !== $filterValue) { | ||
// Use the parameter conversion capabilities of Doctrine | ||
$metadata = $queryBuilder->getEntityManager()->getClassMetadata($context->getEntity()->getFqcn()); | ||
$relatedEntityFqcn = $metadata->getAssociationTargetClass($filterProperty); | ||
$relatedEntityMetadata = $queryBuilder->getEntityManager()->getClassMetadata($relatedEntityFqcn); | ||
$type = $relatedEntityMetadata->getTypeOfField($metadata->getSingleIdentifierFieldName()); | ||
if (Type::hasType($type)) { | ||
$doctrineType = Type::getType($type); | ||
$platform = $queryBuilder->getEntityManager()->getConnection()->getDatabasePlatform(); | ||
$filterValue = $doctrineType->convertToDatabaseValue($filterValue, $platform); | ||
} | ||
$rootAlias = current($queryBuilder->getRootAliases()); | ||
$associationMapping = $metadata->getAssociationMapping($filterProperty); | ||
if (in_array($associationMapping['type'], [ClassMetadata::ONE_TO_MANY, ClassMetadata::MANY_TO_MANY], true)) { | ||
$queryBuilder->andWhere(':filterValue MEMBER OF '.sprintf('%s.%s', $rootAlias, $filterProperty)) | ||
->setParameter('filterValue', $filterValue); | ||
} else { | ||
$queryBuilder->andWhere(sprintf('%s.%s', $rootAlias, $filterProperty) . ' = :filterValue') | ||
->setParameter('filterValue', $filterValue); | ||
} | ||
} | ||
$field = $fields->getByProperty($filterProperty); | ||
if ($field instanceof FieldDto) { | ||
$fields->unset($field); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this into a separate method to keep the index action method simple to understand?
Not sur of what's the best between creating a new createEmbededIndexQueryBuilder()
or something like filterEmbededQueryBuilder()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving it is no problem, as I said - this is a rough draft that needs lots of work :)
As for the second point - maybe creating dedicated embedded(index|detail|edit|new|delete)
actions or even rolling a EmbeddedAbstractController
might be a better way of doing it, but then you have to maintain similar code. So the question is - what would be a better approach to refactor here so it is better long term? Those action methods already are pretty sizeable and adding to them might be a bit overkill :)
Unset all query parameters on the initial embedded crud URL
@psihius anything new here? Wondering if you are still working on this feature... |
Note: this is a WIP and a Request For Comments aka feedback. This needs a lot more development, especially on making things work via AJAX and having a dedicated "embedded" layout, because right now it does not have as smooth functionality as it needs to. Also, a bunch of JS is commented out because I did not get to it yet. Filters are gonna be a major headache and probably would need improvements overall. This might turn into an epic of its own.
This is the ability to embed a whole data grid "index" page into a form via the
EmbedField::new('relation')
This was based on #3543 PR, but a lot has changed since 3.x days and that PR needed a full re-work and bigger changes to the EA.
Lots to work on:
All feedback, patches and discussion are welcome. There's a wide field of discussion on how to approach this and implement it - I am thinking that we probably should have a dedicated
embedded_layout
form and have a dedicated template for the embedded grid rather than doing a single block render like it's doing now.