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

Fix Breadcrumbs into the page #1564

Merged
merged 7 commits into from
Aug 23, 2022
Merged

Conversation

eerison
Copy link
Contributor

@eerison eerison commented Aug 18, 2022

Subject

I am targeting this branch, because it was breaking the pipeline in 4.x branch.

Closes #1497

Changelog

### Changed
- Changed `page` context to `sonata.page.block.breadcrumb` used in `src/Resources/views/layout.html.twig` file

* Create test for templateManager

* Cover breadcrumb html
 into 3.x-into-4.x

� Conflicts:
�	composer.json
�	tests/Page/TemplateManagerTest.php
@eerison eerison force-pushed the 3.x-into-4.x branch 3 times, most recently from 29cb2b3 to 9f051be Compare August 18, 2022 06:28
@eerison
Copy link
Contributor Author

eerison commented Aug 18, 2022

Hey @VincentLanglet

it's the correct code for the test, But as expected it'll fail because the breadcrumbs are not returning into the page!

is it fine wait until I find out the issue, or should we skip this test and merge, and after that I open a new PR with the fix for this bug?

@eerison
Copy link
Contributor Author

eerison commented Aug 18, 2022

I guess this problem is related with: https://github.com/sonata-project/SonataPageBundle/blob/4.x/src/Block/BreadcrumbBlockService.php

the getMenu was not used, anymore :/

@VincentLanglet
Copy link
Member

Hey @VincentLanglet

it's the correct code for the test, But as expected it'll fail because the breadcrumbs are not returning into the page!

is it fine wait until I find out the issue, or should we skip this test and merge, and after that I open a new PR with the fix for this bug?

Sure, we can wait the fix

@eerison
Copy link
Contributor Author

eerison commented Aug 22, 2022

Ok as I was suspecting this bug was introduced in SEO refactoring

https://github.com/sonata-project/SonataPageBundle/pull/1483/files#diff-f0461df8f4a53195f2b565ad37746df1e8076ff748edb18c3e2689581f2db4caR87

is there any reason to use this return sonata.page.block.breadcrumb?

because it was passing page value before.

I changed the context passed by template to sonata.page.block.breadcrumb, I would say it make more sense then page

But I just would like to know if there is some thing else for this getName method with this value!

cc @Daric971

@eerison
Copy link
Contributor Author

eerison commented Aug 22, 2022

Hey @jordisala1991 could you help me here with this phpstan errors?

@VincentLanglet
Copy link
Member

ProxyQuery is now generic.

ProxyQueryInterface<object>

And for

Parameter #1 $twig of class Sonata\PageBundle\Page\TemplateManager constructor expects Twig\Environment, object|null given.

You have to assert

$twig = $container->get('twig');
\assert($twig instanceof Environment)

@eerison eerison force-pushed the 3.x-into-4.x branch 2 times, most recently from 9f2fce2 to 943240e Compare August 22, 2022 09:18
src/Admin/SharedBlockAdmin.php Outdated Show resolved Hide resolved
@eerison
Copy link
Contributor Author

eerison commented Aug 22, 2022

Ok I got those 2 errors

Error: src/Admin/SharedBlockAdmin.php:41:68: MoreSpecificReturnType: The declared return type 'Sonata\AdminBundle\Datagrid\ProxyQueryInterface<Sonata\PageBundle\Model\PageBlockInterface>' for Sonata\PageBundle\Admin\SharedBlockAdmin::configureQuery is more specific than the inferred return type 'Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery&Sonata\AdminBundle\Datagrid\ProxyQueryInterface<Sonata\PageBundle\Model\PageBlockInterface>' (see https://psalm.dev/070)

Error: src/Admin/SharedBlockAdmin.php:50:16: LessSpecificReturnStatement: The type 'Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery&Sonata\AdminBundle\Datagrid\ProxyQueryInterface<Sonata\PageBundle\Model\PageBlockInterface>' is more general than the declared return type 'Sonata\AdminBundle\Datagrid\ProxyQueryInterface<Sonata\PageBundle\Model\PageBlockInterface>' for Sonata\PageBundle\Admin\SharedBlockAdmin::configureQuery (see https://psalm.dev/12[9](https://github.com/sonata-project/SonataPageBundle/runs/7948691625?check_suite_focus=true#step:5:10))
🐑 results sent to shepherd.dev 🐑
Error: Process completed with exit code 2.

any idea how to solve @VincentLanglet

@VincentLanglet
Copy link
Member

VincentLanglet commented Aug 22, 2022

MoreSpecificReturnType: The declared return type 'Sonata\AdminBundle\Datagrid\ProxyQueryInterface<Sonata\PageBundle\Model\PageBlockInterface>' for Sonata\PageBundle\Admin\SharedBlockAdmin::configureQuery is more specific than the inferred return type 'Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery&Sonata\AdminBundle\Datagrid\ProxyQueryInterface<Sonata\PageBundle\Model\PageBlockInterface>

Isn't a bug ?

Sonata\AdminBundle\Datagrid\ProxyQueryInterface<Sonata\PageBundle\Model\PageBlockInterface>
is considered as more specific than
Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery&Sonata\AdminBundle\Datagrid\ProxyQueryInterface<Sonata\PageBundle\Model\PageBlockInterface>
but
Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery&Sonata\AdminBundle\Datagrid\ProxyQueryInterface<Sonata\PageBundle\Model\PageBlockInterface>
is
Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery
AND
Sonata\AdminBundle\Datagrid\ProxyQueryInterface<Sonata\PageBundle\Model\PageBlockInterface>

So to me
Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery&Sonata\AdminBundle\Datagrid\ProxyQueryInterface<Sonata\PageBundle\Model\PageBlockInterface>
is more specific than Sonata\AdminBundle\Datagrid\ProxyQueryInterface<Sonata\PageBundle\Model\PageBlockInterface> not the opposite.

Do you mind looking in the issues/creating an issue on https://github.com/vimeo/psalm/issues ?

Moreover, if it's a real issue, I think it would have been reported by phpstan.

@eerison eerison force-pushed the 3.x-into-4.x branch 6 times, most recently from 4631a51 to ec7c892 Compare August 22, 2022 13:57
@eerison eerison force-pushed the 3.x-into-4.x branch 3 times, most recently from 5f0adf6 to 94cf542 Compare August 22, 2022 14:21
@eerison
Copy link
Contributor Author

eerison commented Aug 22, 2022

Yeah there is a bug, But I guess it's not related with psalm

Because the code was importing a different ProxyQuery (from Datagrid), But the method returns ProxyQuery from admin

src/Admin/SharedBlockAdmin.php Outdated Show resolved Hide resolved
src/Admin/SharedBlockAdmin.php Outdated Show resolved Hide resolved
@VincentLanglet
Copy link
Member

Yeah there is a bug, But I guess it's not related with psalm

Because the code was importing a different ProxyQuery (from Datagrid), But the method returns ProxyQuery from admin

That's not an issue.
The ProxyQuery implements the ORMProxyQueryInterface which implements ProxyQueryInterface from AdminBundle.
So we do return a ProxyQueryInterface.

I still believe it's an issue with psalm.

@eerison eerison force-pushed the 3.x-into-4.x branch 3 times, most recently from 1130c52 to 903b7fb Compare August 23, 2022 06:54
@sonata-project sonata-project deleted a comment from eerison Aug 23, 2022
@sonata-project sonata-project deleted a comment from eerison Aug 23, 2022
@sonata-project sonata-project deleted a comment from eerison Aug 23, 2022
src/Admin/SharedBlockAdmin.php Outdated Show resolved Hide resolved
@eerison eerison marked this pull request as ready for review August 23, 2022 08:13
@eerison eerison changed the title 3.x into 4.x Fix Breadcrumbs into the page Aug 23, 2022
@VincentLanglet VincentLanglet merged commit b002bde into sonata-project:4.x Aug 23, 2022
@eerison eerison deleted the 3.x-into-4.x branch August 23, 2022 08:22
@@ -54,6 +54,8 @@ public static function getSubscribedServices(): array
}

/**
* @param ProxyQueryInterface<object> $query
Copy link
Member

Choose a reason for hiding this comment

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

But if we know this is batch for pages, shouldnt this objet be PageInterface?

cc @VincentLanglet

Copy link
Member

Choose a reason for hiding this comment

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

Indeed

@@ -35,6 +35,8 @@ public static function getSubscribedServices(): array
}

/**
* @param ProxyQueryInterface<object> $query
Copy link
Member

Choose a reason for hiding this comment

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

Same but with SnapshotInterface

Copy link
Member

Choose a reason for hiding this comment

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

Indeed

<div class="row">
{{ sonata_block_render_event('breadcrumb', { 'context': 'page', 'current_uri': app.request.requestUri }) }}
<div class="row page-breadcrumb">
{{ sonata_block_render_event('breadcrumb', { 'context': 'sonata.page.block.breadcrumb', 'current_uri': app.request.requestUri }) }}
Copy link
Member

Choose a reason for hiding this comment

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

do we know why this context changed? should we revert something somewhere?

Also if this code changes is there any docs to update?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

check this comment please : #1564 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But this bug was introduced here: https://github.com/sonata-project/SonataPageBundle/pull/1483/files#diff-f0461df8f4a53195f2b565ad37746df1e8076ff748edb18c3e2689581f2db4caR87

I guess he was just following how the stuffs were made in others parts, But in 3.x it was using page

and when added this method, it was changed!

I choose to use sonata.page.block.breadcrumb because it's more explainable then page, But yes, It's a BC!

because if someone is using sonata_block_render_event passing page, it won't work!

I could back to page, But I guess it's not the correct correct for breadcrumb, sonata.page.block.breadcrumb make more sense!

Copy link
Member

Choose a reason for hiding this comment

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

I made a mistake there, imo it should be page

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well we can back this for page :),

I'll open a PR for this ;)

Copy link
Member

Choose a reason for hiding this comment

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

Yes if you can open a PR to fix the things I mentioned it would be great :) thanks!

Copy link
Member

Choose a reason for hiding this comment

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

I opened #1570

// Mock Snapshot manager
$snapshotManagerMock = $this->createMock(SnapshotManagerInterface::class);
$transformerMock = $this->createMock(TransformerInterface::class);
$cmsSnapshotManagerMock = new CmsSnapshotManager($snapshotManagerMock, $transformerMock);
Copy link
Member

Choose a reason for hiding this comment

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

I recommend to not name variables with mock suffix , this one is a mistake for example, it is not a mock

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true :/

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.

3 participants