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

Introduce SonataConfiguration class #6640

Merged
merged 1 commit into from
Dec 5, 2020

Conversation

franmomu
Copy link
Member

@franmomu franmomu commented Nov 30, 2020

Subject

Part of #6624

This class (I wasn't sure in which folder should go) will handle configuration for sonata which is currently holded by Pool class.

It adds a global twig sonata_config variable in order to replace the current sonata_admin variable whose name could mislead to think that is some kind of admin.

sonata_admin is registered as global twig variable in:

public function process(ContainerBuilder $container)
{
$container->getDefinition('twig')
->addMethodCall('addGlobal', ['sonata_admin', new Reference('sonata.admin.twig.global')]);
}

->set('sonata.admin.twig.global', GlobalVariables::class)
->public()
->args([
new ReferenceConfigurator('sonata.admin.pool'),
'%sonata.admin.configuration.mosaic_background%',
])
->alias(GlobalVariables::class, 'sonata.admin.twig.global')

All GlobalVariables methods have been deprecated:

  • url and objectUrl were added in 964853c, I haven't found any use, this is usually done though the AdminInterface::generateUrl and AdminInterface::generateObjectUrl.
  • getAdminPool shouldn't be used in twig, it still has one usage, I'll comment later.
  • getMosaicBackground has been replaced by SonataConfiguration::getOption('mosaic_background').

I added a GroupExtension Twig extension in order to handle some logic that was done in twig directly.

I am targeting this branch, because these changes are BC.

Changelog

### Added
- Added `SonataConfiguration` class to handle sonata global configuration.
- Added global Twig `sonata_config` to access global configuration from Twig.
### Deprecated
- Deprecated `Pool::getTitle()` method.
- Deprecated `Pool::getTitleLogo()` method.
- Deprecated `Pool::getOption()` method.
- Deprecated global Twig `sonata_admin` variable.

The only thing left is in dashboard.html.twig where there are a couple of calls:

{{ sonata_block_render_event('sonata.admin.dashboard.top', { 'admin_pool': sonata_admin.adminPool }) }}

{{ sonata_block_render_event('sonata.admin.dashboard.bottom', { 'admin_pool': sonata_admin.adminPool }) }}

which I haven't used, but I guess someone using this event could inject the Pool service in the listener directly.

@franmomu franmomu added the minor label Nov 30, 2020
@franmomu franmomu mentioned this pull request Nov 30, 2020
3 tasks
@franmomu franmomu force-pushed the create_configuration branch 2 times, most recently from 1834a75 to f58b650 Compare November 30, 2020 18:04
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.

Can we chose another directory ?
There is already too much file in the Admin directory IMHO.

Everything is Admin-related, since it's an Admin bundle.

@franmomu
Copy link
Member Author

Can we chose another directory ?

Sure, I said in the description that I didn't know where to put it, so I'm open to suggestions, any idea where?

@VincentLanglet
Copy link
Member

any idea where?

No. I currently don't find better than admin.
But maybe the problem with this "too big directory" are the others files:

  • BaseFieldDescription, FieldDescriptionCollection, FieldDescriptionInterface and FieldDescriptionRegistryInterface could be in a specific directory.
  • BreadcrumbsBuilder, BreadcrumbsBuilderInterface, MenuBuilderInterface could be in the Builder directory.

@franmomu
Copy link
Member Author

Maybe just a Config or Configuration directory.

@greg0ire
Copy link
Contributor

Admin is indeed probably not the right place since it does not relate to an Admin object such as UserAdmin. Instead, this is the global configuration of the whole administration backend, which means it's common, shared, global, cross-cutting. I'd either put it in a directory named like one of those words, or just drop it next to SonataAdminBundle.php since it's so global. Do you foresee the need to have other classes being grouped with that one?

@franmomu franmomu force-pushed the create_configuration branch 2 times, most recently from 1e85057 to 2034bef Compare December 1, 2020 09:14
@franmomu
Copy link
Member Author

franmomu commented Dec 1, 2020

I've moved it to the root directory, I don't see other possible classes going in the Configuration directory right now.

@OskarStark
Copy link
Member

Root directory is fine, like @greg0ire explained 👌🏻

@franmomu franmomu force-pushed the create_configuration branch from 2034bef to fac90c9 Compare December 2, 2020 18:24
VincentLanglet
VincentLanglet previously approved these changes Dec 4, 2020
@VincentLanglet VincentLanglet requested a review from a team December 4, 2020 19:58
OskarStark
OskarStark previously approved these changes Dec 5, 2020
UPGRADE-3.x.md Outdated
@@ -4,12 +4,30 @@ UPGRADE 3.x
UPGRADE FROM 3.xx to 3.xx
=========================

### Deprecated `admin_pool` parameter in `sonata.admin.dashboard.top` and `onata.admin.dashboard.bottom` block events.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
### Deprecated `admin_pool` parameter in `sonata.admin.dashboard.top` and `onata.admin.dashboard.bottom` block events.
### Deprecated `admin_pool` parameter in `sonata.admin.dashboard.top` and `sonata.admin.dashboard.bottom` block events.

@@ -27,6 +27,8 @@ class GlobalVariablesCompilerPass implements CompilerPassInterface
public function process(ContainerBuilder $container)
{
$container->getDefinition('twig')
->addMethodCall('addGlobal', ['sonata_configuration', new Reference('sonata.admin.configuration')])
Copy link
Member

Choose a reason for hiding this comment

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

No blocker, more a personal choice. I would prefer sonata_config

Copy link
Member Author

Choose a reason for hiding this comment

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

I like it, changed.

Copy link
Member

@core23 core23 left a comment

Choose a reason for hiding this comment

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

There is a typo in the docs

@SonataCI
Copy link
Collaborator

SonataCI commented Dec 5, 2020

Could you please rebase your PR and fix merge conflicts?

core23
core23 previously approved these changes Dec 5, 2020
@franmomu franmomu requested a review from a team December 5, 2020 15:31
@franmomu franmomu mentioned this pull request Dec 5, 2020
@SonataCI
Copy link
Collaborator

SonataCI commented Dec 5, 2020

Could you please rebase your PR and fix merge conflicts?

@SonataCI
Copy link
Collaborator

SonataCI commented Dec 5, 2020

Could you please rebase your PR and fix merge conflicts?

VincentLanglet
VincentLanglet previously approved these changes Dec 5, 2020
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.

The changelog and the commit message should be updated about
sonata_config

This class will handle configuration for sonata which is currently
holded by Pool class.

It adds a global twig "sonata_config" variable in order to
replace the current "sonata_admin" variable which all its methods
are deprecated.
@VincentLanglet VincentLanglet merged commit ad8a050 into sonata-project:3.x Dec 5, 2020
@VincentLanglet
Copy link
Member

Thanks @franmomu

@franmomu franmomu deleted the create_configuration branch December 5, 2020 21:15
@mleko64
Copy link

mleko64 commented Dec 9, 2020

@franmomu You forgot change variable "sonata_admin" to "sonata_config" in src/Resources/views/Pager/base_links.html.twig template file (line 27).

@franmomu
Copy link
Member Author

franmomu commented Dec 9, 2020

@franmomu You forgot change variable "sonata_admin" to "sonata_config" in src/Resources/views/Pager/base_links.html.twig template file (line 27).

Thanks for reporting @mleko64! I've created #6677

@@ -87,6 +98,11 @@ public function getAdminPool()
*/
public function url($code, $action, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
{
@trigger_error(sprintf(
Copy link
Member

@core23 core23 Mar 2, 2021

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I would recommend to pass the PageAdmin or the AdminPool in the BlockService https://github.com/sonata-project/SonataPageBundle/blob/3.x/src/Block/PageListBlockService.php

And then calling pageAdmin.generateUrl()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants