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

How to extend the ArticleController #627

Open
thenetexperts opened this issue Oct 4, 2022 · 0 comments
Open

How to extend the ArticleController #627

thenetexperts opened this issue Oct 4, 2022 · 0 comments
Labels

Comments

@thenetexperts
Copy link

thenetexperts commented Oct 4, 2022

Q A
Bug? no
New Feature? yes
SuluArticleBundle Version latest
Sulu Version latest

I was looking for a way to add custom columns to different article types (news, reports, agencies ect), and found out I have to extend from the bundle's ArticleController.

The simple extension off of the class did not work, and I talked to @luca-rath on slack about it. As usual Luca had the solution ready.

During my research before asking on slack, I found many people asking for this as they failed doing so.
My proposal is to extend the documentation to take note of this.

The working approach to make it work:

Add this section to /config/routes/sulu_article_admin.yaml

sulu_article.article:
    type: rest
    resource: App\Controller\Admin\ArticleController
    name_prefix: sulu_article.
    prefix: /admin/api

Add the extending class service definition explicitly to services.yaml

    App\Controller\Admin\ArticleController:
        public: true
        arguments:
            - '@fos_rest.view_handler'
            - '@sulu_document_manager.document_manager'
            - '@sulu.content.mapper'
            - '@sulu_document_manager.metadata_factory.base'
            - '@sulu_core.list_rest_helper'
            - '@es.manager.default'
            - '@sulu_article.view_document.factory'
            - '@form.factory'
            - '@sulu_hash.request_hash_checker'
            - '@sulu_security.security_checker'
            - '%sulu_article.display_tab_all%'
            - '@security.token_storage'
        tags: [{name: 'sulu.context', context: 'admin'}]

After this, clear cache and the new overriding class will be used for the articles section in the Admin.

(The approach is in line with the symfony documentation though for some reason the tags need to be added explicitly even if the src/Controller/Admin resource is assigned the tags already somewhere in the services.yaml).

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

No branches or pull requests

2 participants