Search code examples
symfonyshopwareshopware6

How do I add Shopware 6 Administration configuration from inside a Symfony bundle?


I'm trying to add configuration to the administration area of Shopware 6 from inside a Symfony bundle.

I have followed the official documentation, but nothing gets displayed in the administration area.

The bundle config resides under the path

MyBundle/Resources/config/config.xml

with the content from the documentation

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/platform/trunk/src/Core/System/SystemConfig/Schema/config.xsd">
    <card>
        <title>Basic Configuration</title>
        <title lang="de-DE">Grundeinstellungen</title>
        <input-field>
            <name>email</name>
            <copyable>true</copyable>
            <label>eMail address</label>
            <label lang="de-DE">E-Mail Adresse</label>
            <placeholder>[email protected]</placeholder>
            <placeholder lang="de-DE">[email protected]</placeholder>
            <helpText>Please fill in your personal eMail address</helpText>
            <helpText lang="de-DE">Bitte trage deine persönliche E-Mail Adresse ein</helpText>
        </input-field>
    </card>
</config>

Even after deleting the cache and rebuilding the administration via console commands, it does not show up.


Solution

  • Update: In your MyBundle.php make sure you extend Shopware\Core\Framework\Bundle instead of Symfony\Component\HttpKernel\Bundle\Bundle. This should enable most capabilities of actual plugins, including the config.xml getting parsed. The exception would of course be the lifecycle events commonly associated with plugins like installation, activation, deinstallation etc via the extension manager.

    use Shopware\Core\Framework\Bundle;
    
    class MyBundle extends Bundle
    {
        protected $name = 'MyBundle';
    }
    

    This will however not make your bundle appear among regular plugins in the administration. But since the config.xml is being parsed you can access the page with the rendered fields directly via the corresponding URL:

    http://localhost/admin#/sw/extension/config/MyBundle
    

    So in theory you only need to extend the administration and place a link to that page somewhere, since your bundle is not listed as a plugin.


    Old answer (referring to using a plugin instead):

    This looks good. You refer to what you have as a Symfony bundle. While a plugin is an extension of a bundle, parsing the config.xml happens only with actual plugins.

    Unless installed via composer the file should then be located at custom/plugins/MyBundle/Resources/config/config.xml or custom/static-plugins/MyBundle/Resources/config/config.xml and MyBundle.php should extend Shopware\Core\Framework\Plugin. The plugin must then be installed either by administration or via cli bin/console plugin:install MyBundle --activate