sonata-project/SonataPageBundle

CmsPageRouter not working

tdumalin opened this issue · 0 comments

Environment

Sonata packages

show

$ composer show --latest 'sonata-project/*'
Info from https://repo.packagist.org: #StandWithUkraine
Color legend:
- patch or minor release available - update recommended
- major release available - update possible
- up to date version

Direct dependencies required in composer.json:
sonata-project/admin-bundle              4.20.0 4.22.2 The missing Symfony Admin Generator
sonata-project/doctrine-orm-admin-bundle 4.8.0  4.9.1  Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/media-bundle              4.5.1  4.5.1  Symfony SonataMediaBundle
sonata-project/page-bundle               4.0.0  4.0.0  This bundle provides a Site and Page management through container and block services

Transitive dependencies not required in composer.json:
sonata-project/block-bundle              4.19.0 4.19.0 Symfony SonataBlockBundle
sonata-project/cache                     2.2.0  2.2.0  Cache library
Package sonata-project/cache is abandoned, you should avoid using it. No replacement was suggested.
sonata-project/doctrine-extensions       1.18.1 2.1.0  Doctrine2 behavioral extensions
sonata-project/exporter                  3.0.0  3.1.1  Lightweight Exporter library
sonata-project/form-extensions           1.18.0 1.18.0 Symfony form extensions
sonata-project/seo-bundle                3.5.0  3.5.0  Symfony SonataSeoBundle
sonata-project/twig-extensions           1.12.0 2.0.0  Sonata twig extensions

Symfony packages

show

$ composer show --latest 'symfony/*'
Color legend:
- patch or minor release available - update recommended
- major release available - update possible
- up to date version

Direct dependencies required in composer.json:
symfony/console                    v5.4.15 v6.2.3  Eases the creation of beautiful and testable command line interfaces
symfony/debug-bundle               v5.4.11 v6.2.1  Provides a tight integration of the Symfony VarDumper component and the ServerLogCommand from MonologBridge into the Symfon...
symfony/dependency-injection       v5.4.13 v6.2.3  Allows you to standardize and centralize the way objects are constructed in your application
symfony/dotenv                     v5.4.5  v6.2.0  Registers environment variables from a .env file
symfony/flex                       v1.19.3 v2.2.4  Composer plugin for Symfony
symfony/framework-bundle           v5.4.14 v6.2.3  Provides a tight integration between Symfony components and the Symfony full-stack framework
symfony/mailer                     v5.4.15 v6.2.2  Helps sending emails
symfony/maker-bundle               v1.47.0 v1.48.0 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing bo...
symfony/monolog-bundle             v3.8.0  v3.8.0  Symfony MonologBundle
symfony/proxy-manager-bridge       v5.4.6  v6.2.0  Provides integration for ProxyManager with various Symfony components
symfony/runtime                    v5.4.11 v6.2.0  Enables decoupling PHP applications from global state
symfony/security-bundle            v5.4.11 v6.2.3  Provides a tight integration of the Security component into the Symfony full-stack framework
symfony/serializer                 v5.4.15 v6.2.3  Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like...
symfony/stopwatch                  v5.4.13 v6.2.0  Provides a way to profile code
symfony/twig-bundle                v5.4.8  v6.2.3  Provides a tight integration of Twig into the Symfony full-stack framework
symfony/ux-autocomplete            v2.4.0  v2.6.1  JavaScript Autocomplete functionality for Symfony
symfony/ux-dropzone                v2.4.0  v2.6.1  File input dropzones for Symfony Forms
symfony/ux-live-component          v2.4.0  v2.6.1  Live components for Symfony
symfony/ux-swup                    v2.4.0  v2.6.1  Swup integration for Symfony
symfony/ux-twig-component          v2.4.0  v2.6.1  Twig components for Symfony
symfony/validator                  v5.4.15 v6.2.3  Provides tools to validate values
symfony/web-profiler-bundle        v5.4.14 v6.2.4  Provides a development tool that gives detailed information about the execution of any request
symfony/webpack-encore-bundle      v1.16.0 v1.16.0 Integration with your Symfony app & Webpack Encore!
symfony/yaml                       v5.4.14 v6.2.2  Loads and dumps YAML files

Transitive dependencies not required in composer.json:
symfony/asset                      v5.4.13 v6.2.0  Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files
symfony/cache                      v5.4.15 v6.2.4  Provides extended PSR-6, PSR-16 (and tags) implementations
symfony/cache-contracts            v2.5.2  v3.2.0  Generic abstractions related to caching
symfony/config                     v5.4.11 v6.2.0  Helps you find, load, combine, autofill and validate configuration values of any kind
symfony/css-selector               v5.4.11 v6.2.3  Converts CSS selectors to XPath expressions
symfony/deprecation-contracts      v3.1.1  v3.2.0  A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge            v5.4.15 v6.2.3  Provides integration for Doctrine with various Symfony components
symfony/error-handler              v5.4.15 v6.2.3  Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher           v5.4.9  v6.2.2  Provides tools that allow your application components to communicate with each other by dispatching events and listening to...
symfony/event-dispatcher-contracts v3.1.1  v3.2.0  Generic abstractions related to dispatching event
symfony/expression-language        v5.4.14 v6.2.2  Provides an engine that can compile and evaluate expressions
symfony/filesystem                 v5.4.13 v6.2.0  Provides basic utilities for the filesystem
symfony/finder                     v5.4.11 v6.2.3  Finds files and directories via an intuitive fluent interface
symfony/form                       v5.4.15 v6.2.3  Allows to easily create, process and reuse HTML forms
symfony/http-client                v5.4.15 v6.2.2  Provides powerful methods to fetch HTTP resources synchronously or asynchronously
symfony/http-client-contracts      v2.5.2  v3.2.0  Generic abstractions related to HTTP clients
symfony/http-foundation            v5.4.15 v6.2.2  Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                v5.4.15 v6.2.4  Provides a structured process for converting a Request into a Response
symfony/intl                       v5.4.15 v6.2.0  Provides a PHP replacement layer for the C intl extension that includes additional data from the ICU library
symfony/mime                       v5.4.14 v6.2.2  Allows manipulating MIME messages
symfony/monolog-bridge             v5.4.10 v6.2.2  Provides integration for Monolog with various Symfony components
symfony/options-resolver           v5.4.11 v6.2.0  Provides an improved replacement for the array_replace PHP function
symfony/password-hasher            v5.4.11 v6.2.0  Provides password hashing utilities
symfony/polyfill-intl-grapheme     v1.26.0 v1.27.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu          v1.26.0 v1.27.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn          v1.26.0 v1.27.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer   v1.26.0 v1.27.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring          v1.26.0 v1.27.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php73             v1.26.0 v1.27.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80             v1.26.0 v1.27.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/polyfill-php81             v1.26.0 v1.27.0 Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions
symfony/process                    v5.4.11 v6.2.0  Executes commands in sub-processes
symfony/property-access            v5.4.15 v6.2.3  Provides functions to read and write from/to an object or array using a simple string notation
symfony/property-info              v5.4.15 v6.2.3  Extracts information about PHP class' properties using metadata of popular sources
symfony/routing                    v5.4.15 v6.2.3  Maps an HTTP request to a set of configuration variables
symfony/security-acl               v3.3.2  v3.3.2  Symfony Security Component - ACL (Access Control List)
symfony/security-core              v5.4.15 v6.2.2  Symfony Security Component - Core Library
symfony/security-csrf              v5.4.11 v6.2.0  Symfony Security Component - CSRF Library
symfony/security-guard             v5.4.13 v5.4.13 Symfony Security Component - Guard
symfony/security-http              v5.4.15 v6.2.2  Symfony Security Component - HTTP Integration
symfony/service-contracts          v2.5.2  v3.2.0  Generic abstractions related to writing services
symfony/string                     v5.4.15 v6.2.2  Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way
symfony/templating                 v5.4.11 v6.2.0  Provides all the tools needed to build any kind of template system
symfony/translation                v5.4.14 v6.2.3  Provides tools to internationalize your application
symfony/translation-contracts      v2.5.2  v3.2.0  Generic abstractions related to translation
symfony/twig-bridge                v5.4.14 v6.2.3  Provides integration for Twig with various Symfony components
symfony/var-dumper                 v5.4.14 v6.2.3  Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter               v5.4.10 v6.2.3  Allows exporting any serializable PHP data structure to plain PHP code

PHP version

$ php -v
PHP 8.1.10 (cli) (built: Sep  1 2022 21:43:31) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.10, Copyright (c), by Zend Technologies
    with Xdebug v3.1.5, Copyright (c) 2002-2022, by Derick Rethans

Subject

The CmsPageRouter seems to not work any more when using a page as first parameter of generate.

Minimal repository with the bug

Steps to reproduce

Create a page entity and use

<?php

/** @var PageInterface */
$page = '...';
$this->generateUrl($page);

or in twig template

{{ path(page) }}

After searching a litte into symfony documentation, i found this:

<?php

namespace Symfony\Cmf\Component\Routing;

//...
class ChainRouter
{
//...
    /**
     * {@inheritdoc}
     *
     * @param mixed $name
     *
     * The CMF routing system used to allow to pass route objects as $name to generate the route.
     * Since Symfony 5.0, the UrlGeneratorInterface declares $name as string. We widen the contract
     * for BC but deprecate passing non-strings.
     * Instead, Pass the RouteObjectInterface::OBJECT_BASED_ROUTE_NAME as route name and the object
     * in the parameters with key RouteObjectInterface::ROUTE_OBJECT.
     *
     * Loops through all registered routers and returns a router if one is found.
     * It will always return the first route generated.
     */
    public function generate($name, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH)
    {
    }
}

So may be the goog way to genreate page url is by doing

$this->generateUrl(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, [
     RouteObjectInterface::ROUTE_OBJECT => $page
]);

and in twig:

{{ path('cmf_routing_object', {
     '_route_object': page
}) }}

Expected results

The page page path url

Actual results

TypeError:
Symfony\Bundle\FrameworkBundle\Controller\AbstractController::generateUrl(): Argument #1 ($route) must be of type string, App\Entity\SonataPage given, called in /srv/app/src/Controller/Admin/TestController.php on line 69

  at vendor/symfony/framework-bundle/Controller/AbstractController.php:140
  at Symfony\Bundle\FrameworkBundle\Controller\AbstractController->generateUrl(object(SonataPage))
     (src/Controller/Admin/TestController.php:69)
  at App\Controller\Admin\TestController->index()
     (vendor/symfony/http-kernel/HttpKernel.php:163)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:75)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:202)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     (vendor/autoload_runtime.php:35)
  at require_once('/srv/app/vendor/autoload_runtime.php')
     (public/index.php:5)