Skip to content

Prepare Preview for new Route Bundle implemention #7867

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

Conversation

alexander-schranz
Copy link
Member

@alexander-schranz alexander-schranz commented Mar 27, 2025

Q A
Bug fix? no
New feature? yes
BC breaks? yes
Deprecations? no
Fixed tickets fixes #
Related issues/PRs #
License MIT
Documentation PR sulu/sulu-docs#

What's in this PR?

Add a new PreviewDefaultsProviderInterface to decouple the Preview Bundle from the RouteBundle. Instead of getObject a new getDefaults is implemented. This should also in future make it easier to create a preview for any none routable entities.

namespace Sulu\Bundle\PreviewBundle\Preview\Provider;

use Sulu\Bundle\PreviewBundle\Preview\PreviewContext;

interface PreviewDefaultsProviderInterface
{
    /**
     * Returns the Route Defaults to render the preview. Should at least return the '_controller' key.
     *
     * @example
     *
     * ```php
     *     return [
     *          'object' => $object,
     *           '_controller' => MyController::class . '::myAction',
     *           'view' => 'my-view',
     *     ];
     * ```
     *
     * @return array<string, mixed>
     */
    public function getDefaults(PreviewContext $previewContext): array;

    /**
     * Called before rendering the preview — can be used to update the values of the defaults.
     *
     * @param array<string, mixed> $defaults
     * @param array<string, mixed> $data
     *
     * @return array<string, mixed>
     */
    public function updateValues(PreviewContext $previewContext, array $defaults, array $data): array;

    /**
     * Called before rendering the preview — called example when template is switched.
     * Can be used to update the values of the defaults.
     *
     * @param array<string, mixed> $defaults
     * @param array<string, mixed> $context
     *
     * @return array<string, mixed>
     */
    public function updateContext(PreviewContext $previewContext, array $defaults, array $context): array;

    public function getSecurityContext(PreviewContext $previewContext): ?string;
}

Syntaxed changed and serialize and deserialized is removed. Currently the Content Bundle does always load the whole entity from Database in serialize method thats why this methods are unnecessary. Still we later could introduced a CachablePreviewDefaultsProviderInterface with serialize and deserialize to improve performance if we want. But most performance improvements where done by not rendering the header and footer always, which is still done as the navigation queries did make most things slow. With future navigation cache maybe also that bottleneck goes away.

Why?

Currently the RouteBundle is deeply integrated into the PreviewRenderer which make usage without RouteBundle hard. This also make it hard to have old and new RouteBundle side by side. So we will move step by step the preview to be independent from Route Bundle.

@alexander-schranz alexander-schranz force-pushed the feature/preview-defaults-provider branch 3 times, most recently from bd71298 to 2e54796 Compare March 28, 2025 14:02
Comment on lines 102 to 114
return [
'object' => $object,
'_controller' => ContentController::class . '::indexAction', // TODO call RouteDefaultsProvider
'view' => 'base', // TODO should provided by RouteDefaultsProvider
];
Copy link
Member Author

Choose a reason for hiding this comment

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

This changes are just a test we need implement this in: #7749 where the new routing will be implemented

@alexander-schranz alexander-schranz force-pushed the feature/preview-defaults-provider branch from 2e54796 to 57ef955 Compare March 28, 2025 14:06
@alexander-schranz alexander-schranz force-pushed the feature/preview-defaults-provider branch 4 times, most recently from ff255f2 to 7fc35f6 Compare March 28, 2025 16:39
@alexander-schranz alexander-schranz added the Feature New functionality not yet included in Sulu label Mar 28, 2025
@alexander-schranz alexander-schranz added this to the Release 3.0 milestone Mar 28, 2025
@alexander-schranz alexander-schranz force-pushed the feature/preview-defaults-provider branch 3 times, most recently from 65c4e1a to 9e1bada Compare March 31, 2025 07:58
@alexander-schranz alexander-schranz force-pushed the feature/preview-defaults-provider branch from 9e1bada to 62891ac Compare March 31, 2025 08:10
@alexander-schranz alexander-schranz marked this pull request as ready for review March 31, 2025 08:41
@alexander-schranz alexander-schranz merged commit 851e849 into sulu:3.0 Mar 31, 2025
9 checks passed
@alexander-schranz alexander-schranz deleted the feature/preview-defaults-provider branch March 31, 2025 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New functionality not yet included in Sulu
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant