Skip to content
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

Add AbstractAdmin::configureExportFields extension point #6348

Merged
merged 1 commit into from
Sep 7, 2020

Conversation

core23
Copy link
Member

@core23 core23 commented Aug 29, 2020

Subject

All extension points are protected and start with configure*. This PRs adds a new one for export fields, so you can define custom fields and can use admin extensions.

I am targeting this branch, because this feature is BC.

Changelog

### Added
- Add `AbstractAdmin::configureExportFields` extension point

@core23 core23 requested a review from a team August 29, 2020 18:45
@codecov-commenter
Copy link

codecov-commenter commented Aug 29, 2020

Codecov Report

Merging #6348 into 3.x will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##                3.x    #6348      +/-   ##
============================================
+ Coverage     77.50%   77.52%   +0.02%     
- Complexity     2602     2605       +3     
============================================
  Files           142      142              
  Lines          7778     7783       +5     
============================================
+ Hits           6028     6034       +6     
+ Misses         1750     1749       -1     
Impacted Files Coverage Δ Complexity Δ
src/Admin/AbstractAdmin.php 79.81% <100.00%> (+0.08%) 465.00 <3.00> (+2.00)
src/Controller/CRUDController.php 92.81% <0.00%> (-0.12%) 173.00% <0.00%> (+1.00%) ⬇️
src/Twig/Extension/SonataAdminExtension.php 88.17% <0.00%> (-0.05%) 83.00% <0.00%> (ø%)
src/Guesser/TypeGuesserChain.php 100.00% <0.00%> (ø) 7.00% <0.00%> (-1.00%)
src/Resources/skeleton/Admin.tpl.php 0.00% <0.00%> (ø) 0.00% <0.00%> (ø%)
src/Resources/skeleton/AdminController.tpl.php 0.00% <0.00%> (ø) 0.00% <0.00%> (ø%)
src/Admin/BaseFieldDescription.php 80.78% <0.00%> (+0.09%) 87.00% <0.00%> (+1.00%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 63242f0...3c813d3. Read the comment docs.

greg0ire
greg0ire previously approved these changes Aug 29, 2020
/**
* @return string[]
*/
protected function configureExportFields(): array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method and signature does not follow the same idea as the other configure: parameter with the initial config and empty body

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my projects, I generally override the getExportFields method this way:

public function getExportFields() 
{
    return ['foo', 'bar'];
}

In these cases, the call

$this->getModelManager()->getExportFields($this->getClass());

Is useless.

This example makes me think that it should be move in the configure method.

Moreover configureExportFields is returning an array in the AdminExtension https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Admin/AbstractAdminExtension.php#L92

And should we add a word in the changelog/upgrade note to say to developers to move the logic from getExportFields to configureExportFields since the first one will be final ?

@core23
Copy link
Member Author

core23 commented Aug 31, 2020

Moreover configureExportFields is returning an array in the AdminExtension https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Admin/AbstractAdminExtension.php#L92

No other configure* method contains any logic, this would be the first one.

We're inconsistent in the handling of array values

This method use references parameters:

  • configureDefaultFilterValues
  • configureDefaultSortValues

While these methods use return values:

  • configureActionButtons
  • configureQuery
  • configureBatchActions

IMHO we should remove the referenced parameters

@wbloszyk
Copy link
Member

IMO return values in configure* methods is confiusing. Each time I want get some data I should use configure method? Look at AbstractAdmin::configureFormFields(ShowMapper $showMapper): void and other methods. We have getter for it getFormFieldDescriptions.

IMHO we should remove the referenced parameters and return values in this methods.

@VincentLanglet
Copy link
Member

IMHO we should remove the referenced parameters and return values in this methods.

When the argument is an object, it's always a reference, so there is no need for returning something.
This is similar to the Symfony buildForm method.

When the argument is an array, it seems more natural to me to return this array instead of using reference.

@wbloszyk
Copy link
Member

wbloszyk commented Aug 31, 2020

Some times ago I present my idea where AbstractAdmin::configureExportFields(ExportMapper $exportMapper). getExportFieldDescriptions will return fields to export. Additional people can create own, non mapped fields(*ExportType) with possibility to create callback.

For methods from #6348 (comment) they should be protected with public getters too.

@core23
Copy link
Member Author

core23 commented Sep 1, 2020

Some times ago I present my idea where AbstractAdmin::configureExportFields(ExportMapper $exportMapper). getExportFieldDescriptions will return fields to export. Additional people can create own, non mapped fields(*ExportType) with possibility to create callback.

For methods from #6348 (comment) they should be protected with public getters too.

I like the idea of an ExportMapper. We should reduce array usage as much as possible. This will also reduce memory footprint and increase performance.

@core23
Copy link
Member Author

core23 commented Sep 1, 2020

Here's the PR #5854 and a similiar one #6080

@VincentLanglet
Copy link
Member

I like the idea of an ExportMapper. We should reduce array usage as much as possible. This will also reduce memory footprint and increase performance.

If we use an ExportMapper (similar to formMapper and showMapper), we'll need an ExportField.
I tried working on ExportField, sonata-project/exporter#341.

But I think we should wait for 4.0 before trying to make this development, in order to not delay anymore the next major.

Anyway, this should not be a blocking point for your PR.

@VincentLanglet VincentLanglet requested a review from a team September 1, 2020 07:11
@wbloszyk
Copy link
Member

wbloszyk commented Sep 1, 2020

I like the idea of an ExportMapper. We should reduce array usage as much as possible. This will also reduce memory footprint and increase performance.

If we use an ExportMapper (similar to formMapper and showMapper), we'll need an ExportField.
I tried working on ExportField, sonata-project/exporter#341.

But I think we should wait for 4.0 before trying to make this development, in order to not delay anymore the next major.

Anyway, this should not be a blocking point for your PR.

Agree, we should release next major version for AdminBundle as fast as it is possible. This ExportMapper feature should be add to 5.0 milestones.

@core23
Copy link
Member Author

core23 commented Sep 4, 2020

So can we merge this, also we will refactor this in the next major release?

@VincentLanglet
Copy link
Member

Is it ok for you @jordisala1991 ? :)

@VincentLanglet VincentLanglet merged commit 8146671 into sonata-project:3.x Sep 7, 2020
@VincentLanglet
Copy link
Member

Thanks @core23

@core23 core23 deleted the export-extension branch September 7, 2020 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants