Add FieldDescriptionInterface#234
Add FieldDescriptionInterface#234VincentLanglet wants to merge 5 commits intosonata-project:3.xfrom VincentLanglet:addFieldDescription
Conversation
|
I fixed all the tests I could @greg0ire. The only one I don't know how to deal with is the Phpstan one. It's maybe related with Since you worked on this, maybe can you help me ? |
|
@greg0ire Seems like doctrine/orm:2.7.3 is needed for fixing Phpstan. Is it ok tu use 2.7.x-dev ATM, since it's in the require-dev section ? @sonata-project/contributors |
|
Are you talking about this: https://github.com/sonata-project/SonataDatagridBundle/runs/697689115?check_suite_focus=true ? I don't reproduce that issue locally on 3.x Trying to reproduce it on fb32707, but |
Yes, I had to require I thinks doctrine/orm#7953 fix the Phpstan error so requiring I didn't find any other way to fix the build. I would say it could be ok to require a non-stable branch, since it's only in the |
|
Ok now I'm reproducing the issue. It's very simple, and it's unrelated to my PR. Rather, it's related to this one: doctrine/orm@26806d0. A simple fix would be to require |
Indeed ! Ready to be reviewed then :) |
|
What I still don't understand is why this doesn't happen on 3.x? Can you please investigate? I think the |
|
@greg0ire More fun, bumping to doctrine/orm ^2,5 is enough 😅 I made the bump in a second commit. |
|
Ok, if you don't want to investigate, say so, I will do it… Looks like I won't understand why doctrine/orm@26806d0 is not annotated with tags on GH, but: So you want to bump the dependency to |
|
What I don't understand is why ^2,4 installs the 2.4.8 version and why ^2.5 installs the 2.7.2 one. |
Done |
…anager` autoload issue
That would be because there are far fewer requirements in 2.4.8: https://github.com/doctrine/orm/blob/v2.4.8/composer.json , which mean Composer can remove lots of dependencies, and use a more recent version of the inflector: |
src/Field/BaseFieldDescription.php
Outdated
|
|
||
| public function mergeOptions(array $options = []): void | ||
| { | ||
| $this->setOptions(array_merge_recursive($this->options, $options)); |
There was a problem hiding this comment.
Maybe we could try to avoid calling array_merge_recursive() (see sonata-project/SonataAdminBundle#6078 (comment)).
There was a problem hiding this comment.
I didn't understood the issue with array_merge_recursive. Can you tell me more about it ?
There was a problem hiding this comment.
My main concern was to create a FieldDescriptionInterface with the same behaviour than the AdminBundle one in order to stop using some duplicated classes and start using the DatagridBundle instead.
This PR sonata-project/SonataAdminBundle#6078 could be done on this bundle when ready I think.
There was a problem hiding this comment.
I didn't understood the issue with array_merge_recursive. Can you tell me more about it ?
The "issue" with array_merge_recursive() is the result it produces if some key is repeated between their arguments. In this example, it converts a value that should be a boolean into an array:
The option "virtual_field" with value array is expected to be of type "bool", but is of type "array".
See https://travis-ci.org/github/sonata-project/SonataAdminBundle/jobs/683117311#L758.
Given that situation, I'd like to avoid the propagation of that issue.
| protected $fieldName; | ||
|
|
||
| /** | ||
| * @var string|int|null the type |
There was a problem hiding this comment.
Why int? Can you explain what are possible int values?
There was a problem hiding this comment.
I just basically moved the file from the AdminBundle to the DatagridBundle
https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Admin/BaseFieldDescription.php#L70
I don't know why int. But it was allowed before.
There was a problem hiding this comment.
I add explanation. For example, ClassMetadata::ONE_TO_MANY is allowed.
There was a problem hiding this comment.
This looks like an architecture problem we should fix when moving this to the right place.
The type property name is to generic to guess the right value. Someone could misuse this.
There was a problem hiding this comment.
This looks like an architecture problem
Maybe, this seems to works well like this currently.
After some investigation,
the type is a string like orm_many_to_one
The only reason to allow int was because of the implementation
public function setAssociationMapping($associationMapping)
{
if (!\is_array($associationMapping)) {
throw new \RuntimeException('The association mapping must be an array');
}
$this->associationMapping = $associationMapping;
$this->type = $this->type ?: $associationMapping['type'];
$this->mappingType = $this->mappingType ?: $associationMapping['type'];
$this->fieldName = $associationMapping['fieldName'];
}
Maybe this implementation is wrong and we should remove the line
$this->type = $this->type ?: $associationMapping['type'];
Maybe we should also makes field private in order to force the usage of getter/setter.
I'll do it tonight.
We should fix when moving this to the right place.
I disagree.
Keep in mind there is mutiple of issue we could fix for datagrid, field descriptions and more.
I can't fix them all.
Fixing some of them is still better than fixing nothing.
I would prefer to focus about the duplicated code between the two bundles.
There was a problem hiding this comment.
After some more investigation, there some times where the type is set as an integer (for orm mapping), when I remove this behaviour, the type is null.
The type is use in DoctrineORMAdmin
$fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType()));
If no template is found (which occur for 1, 2, 3 or null), it then use the Mapping type.
A possible solution would be to restrict type to ?string and mapping type to ?int.
And we'll have to stop throwing error when type is not found.
WDYT @core23 ?
| protected $type; | ||
|
|
||
| /** | ||
| * @var string|int|null the original mapping type |
| } | ||
|
|
||
| /** | ||
| * @param int|string $mappingType |
There was a problem hiding this comment.
Do we need this doc block? Ain't it the same on the interface?
There was a problem hiding this comment.
Isn't easier to have the phpdoc in the file you're reading when you're coding/looking in your vendor, etc ?
I think it's always useful
There was a problem hiding this comment.
Most IDEs can use autocompletion / show methods docs from upper interfaces. The problem is that duplicate docblocks will one day get out of sync.
There was a problem hiding this comment.
I understand.
But because there was no docblocks in the same class in the SonataAdminBundle, a bug was easily introduce in master by restricting the value to ?string.
https://github.com/sonata-project/SonataAdminBundle/blob/master/src/Admin/BaseFieldDescription.php#L227
You proved me that I made the right things by adding this tricky docblock: The first time you read it, you thought that int was a mistake.
Without this docblock I can bet that someone gonna restrict the value to string.
|
Closing in favor of #239 |

Subject
I am targeting this branch, because BC.
Related to #233
I want to
The original AdminBundle FieldDescription expose others methods
FieldDescriptionInterfacein teh Admin-FieldDescriptionInterface.getLabel,getTranslationDomain,getHelpmethods. I will deprecate these methods and recommend to usegetOption($name)instead. Because if we want to introducelabel_translation_parameters,help_translation_domain,help_translation_parameters, etc we don't want to create a new method every time and add it in the interface. You can notice thatgetHelpwas not added in the Interface but it still used in the twig.Changelog