sonata-project / sandbox

[Abandoned] Sonata Project's sandbox
https://sonata-project.org
MIT License
268 stars 198 forks source link

Can t update global page or add a sonata.page.block.container to any page #585

Closed MaraScott closed 8 years ago

MaraScott commented 8 years ago

Hi after installing the sonata-project/sandbox:fix_installation

I have runned this command lines :

app/console cache:clear
app/console sonata:page:update-core-routes --site=all
app/console assets:install --symlink
app/console sonata:page:create-snapshots --site=all

Then I went to the Compose page "global" and try to update the header or footer container which are accessible from the xxxx.demo.sonata-project.org/admin/app/page-page/1/compose

I got this error :

Key "sonata.page.block.container" for array with keys "sonata.seo.block.breadcrumb.homepage, 
sonata.product.block.categories_menu, sonata.page.block.children_pages, 
sonata.product.block.filters_menu, sonata.demo.block.newsletter, sonata.product.block.variations_form, 
sonata.customer.block.recent_customers, sonata.order.block.recent_orders, 
sonata.product.block.recent_products, sonata.product.block.similar_products, 
sonata.block.service.menu, sonata.block.service.rss, sonata.block.service.template, 
sonata.block.service.text, sonata.formatter.block.formatter, sonata.media.block.feature_media, 
sonata.media.block.gallery, sonata.media.block.media, sonata.news.block.recent_comments, 
sonata.news.block.recent_posts, sonata.page.block.breadcrumb, sonata.seo.block.email.share_button, 
sonata.seo.block.facebook.like_box, sonata.seo.block.facebook.like_button, 
sonata.seo.block.facebook.send_button, sonata.seo.block.facebook.share_button, 
sonata.seo.block.pinterest.pin_button, sonata.seo.block.twitter.embed, 
sonata.seo.block.twitter.follow_button, sonata.seo.block.twitter.hashtag_button, 
sonata.seo.block.twitter.mention_button, sonata.seo.block.twitter.share_button" does not exist in 
SonataPageBundle:BlockAdmin:compose_preview.html.twig at line 10.

Here the app/config/sonata/sonata_block.yml


sonata_block:
    context_manager: sonata.page.block.context_manager
    default_contexts: [sonata_page_bundle]

    http_cache:
        listener: true

    menus:
        "SonataDemoBundle:Builder:mainMenu": "Main Menu"

    blocks:
        sonata.admin.block.stats:
            contexts:   [admin]
        sonata.admin.block.admin_list:
            contexts:   [admin]
        sonata.admin.block.search_result:
            contexts:   [admin]

        #sonata.admin_doctrine_orm.block.audit:
        #    contexts:   [admin]

        # Builtin Block
        sonata.block.service.text:
        sonata.block.service.container:
        sonata.block.service.rss:
        sonata.block.service.menu:
        sonata.block.service.template:

        # PageBundle's Blocks
        sonata.page.block.container:
            # cache: sonata.cache.memcached
            # cache: sonata.cache.predis
            # cache: sonata.page.cache.esi # if you are using the PageBundle
            # cache: sonata.block.cache.esi # if you are using the BlockBundle without the PageBundle
        sonata.page.block.children_pages:
        sonata.page.block.breadcrumb:

        # MediaBundle's Blocks
        sonata.media.block.media:
        sonata.media.block.gallery:
        sonata.media.block.feature_media:

        # NewsBundle's Blocks
        sonata.news.block.recent_comments:
        sonata.news.block.recent_posts:

        # Ecommerce's Blocks
        sonata.order.block.recent_orders:
        sonata.product.block.recent_products:
        sonata.product.block.similar_products:
        sonata.product.block.categories_menu:
        sonata.product.block.filters_menu:
        sonata.product.block.variations_form:
        sonata.customer.block.recent_customers:
        sonata.basket.block.nb_items:
            cache: sonata.page.cache.js_async
            contexts: [user]
        sonata.basket.block.nb_items:
            cache: sonata.page.cache.js_async
            contexts: [user]

        # TimelineBundle's Blocks

        sonata.timeline.block.timeline:
        sonata.timeline.block.timeline:
            contexts:   [admin]

        # UserBundle's Blocks
        sonata.user.block.account:
            cache: sonata.page.cache.js_async
            #cache: sonata.page.cache.esi
            contexts: [user]
        sonata.user.block.menu:
            contexts: [user]

        # SeoBundle's Blocks
        sonata.seo.block.email.share_button:
        sonata.seo.block.facebook.like_box:
        sonata.seo.block.facebook.like_button:
        sonata.seo.block.facebook.send_button:
        sonata.seo.block.facebook.share_button:
        sonata.seo.block.pinterest.pin_button:
        sonata.seo.block.twitter.share_button:
        sonata.seo.block.twitter.follow_button:
        sonata.seo.block.twitter.hashtag_button:
        sonata.seo.block.twitter.mention_button:
        sonata.seo.block.twitter.embed:

        sonata.demo.block.newsletter:

        # Formatter
        sonata.formatter.block.formatter:

        sonata.seo.block.breadcrumb.homepage:

and the app/config/sonata/sonata_page.yml


#
# more information can be found here https://sonata-project.org/bundles/page
#
cmf_routing:
    chain:
        routers_by_id:
            # enable the DynamicRouter with high priority to allow overwriting configured routes with content
            #symfony_cmf_routing_extra.dynamic_router: 200
            # enable the symfony default router with a lower priority
            sonata.page.router: 150
            router.default: 100

sonata_page:
    class:
        site:     AppBundle\Entity\Page\Site
        snapshot: AppBundle\Entity\Page\Snapshot
        page:     AppBundle\Entity\Page\Page
        block:    AppBundle\Entity\Page\Block

    multisite:             host_with_path # host
    use_streamed_response: false # set the value to false in debug mode or if the reverse proxy does not handle streamed response

    ignore_uri_patterns:
        - ^/admin(.*)
        - ^/api/(.*)

    ignore_route_patterns:
        - (.*)admin(.*)     # ignore admin route, ie route containing 'admin'
        - ^_(.*)            # ignore symfony routes

    ignore_routes:
        - sonata_page_cache_esi
        - sonata_page_cache_ssi
        - sonata_page_js_sync_cache
        - sonata_page_js_async_cache
        - sonata_cache_esi
        - sonata_cache_ssi
        - sonata_cache_js_async
        - sonata_cache_js_sync
        - sonata_cache_apc

    cache_invalidation:
        service:  sonata.page.cache.invalidation.simple
        recorder: sonata.page.cache.recorder
        classes:
            "Application\Sonata\PageBundle\Entity\Block": getId

    assets:
        stylesheets:
            - assetic/sonata_front_css.css

        javascripts:
            - assetic/sonata_front_js.js

    default_template: default
    templates:
        default:
            path: 'AppBundle::demo_layout.html.twig'
            name: 'default'
            containers:
                 header:
                     name: Header
                     blocks:
                        - sonata.block.service.text
                 content_top:
                     name: Top content
                 content:
                     name: Main content
                 content_bottom:
                     name: Bottom content
                 footer:
                     name: Footer
            matrix:
                 layout: |
                     HHHHHHHH
                     TTTTTTTT
                     CCCCCCCC
                     BBBBBBBB
                     FFFFFFFF

                 mapping:
                     H: header
                     T: content_top
                     C: content
                     B: content_bottom
                     F: footer

        2columns:
            path: 'AppBundle::demo_2columns_layout.html.twig'
            name: '2 columns layout'
            containers:
                 header:
                     name: Header
                 content_top:
                     name: Top content
                 left_col:
                     name: Left content
                 right_col:
                     name: Right content
                 content_bottom:
                     name: Bottom content
                 footer:
                     name: Footer
            matrix:
                 layout: |
                     HHHHHHHH
                     TTTTTTTT
                     LLLLRRRR
                     BBBBBBBB
                     FFFFFFFF

                 mapping:
                     H: header
                     T: content_top
                     L: left_col
                     R: right_col
                     B: content_bottom
                     F: footer

    page_defaults:
        homepage: { decorate: false, enabled: true }

    caches:
        esi:
            token:    add an unique token here # default is a random value
            version:  3                        # version 3 is the default on debian wheezy ...
            servers:
                # you need to ajust this configuration to match your varnish configuration
                - %sonata_page.varnish.command%
        ssi:
            token:    add an unique token here # default is a random value

    catch_exceptions:
        not_found: [404]    # render 404 page with "not_found" key (name generated: _page_internal_error_{key})
        fatal:     [500]    # so you can use the same page for different http errors or specify specific page for each error

# Enable Doctrine to map the provided entities
doctrine:
    orm:
        entity_managers:
            default:
                mappings:
                    SonataPageBundle: ~

@OskarStark @rande

I see two options :

MaraScott commented 8 years ago

Okay I found the solution by myself, it appear that to access container in the admin we need to add them to the available blockService by modifying : In SonataPageBundle/Controller/PageAdminController.php l. 241


[---] $blockServices = $this->get('sonata.block.manager')->getServicesByContext('sonata_page_bundle', false);
[+++] $blockServices = $this->get('sonata.block.manager')->getServicesByContext('sonata_page_bundle', true);
MaraScott commented 8 years ago

@rande Actually, I ll be interested to get your composer.json file