Skip to content

Commit

Permalink
Add info where to add values to config (#1295)
Browse files Browse the repository at this point in the history
  • Loading branch information
Isengo1989 authored Feb 21, 2024
1 parent ae69546 commit a20c59e
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ All you need to do is creating a `config.xml` file inside of a `Resources/config

## Fill your plugin configuration with settings

As we now know how to create your configuration, we can start to fill it with life

* or options to configure, in this case.
As you now know how to create configurations, you can start to fill it with life using various configuration options.

### Cards in your configuration

Expand All @@ -48,8 +46,7 @@ The `config.xml` follows a simple syntax. You can organize the content in `<card
// <plugin root>/src/Resources/config/config.xml
<?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">

xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/shopware/trunk/src/Core/System/SystemConfig/Schema/config.xsd">
<card>
<title>Minimal configuration</title>
<input-field>
Expand All @@ -63,7 +60,7 @@ Please make sure to specify the `xsi:noNamespaceSchemaLocation` as shown above a

### Card Titles

A `<card>` `<title>` is translatable, this is managed via the `lang` attribute. By default the `lang` attribute is set to `en-GB`, to change the locale of a `<title>` just add the attribute as follows:
A `<card>` `<title>` is translatable, this is managed via the `lang` attribute. By default, the `lang` attribute is set to `en-GB`, to change the locale of a `<title>` just add the attribute as follows:

```html
...
Expand Down Expand Up @@ -102,7 +99,7 @@ Your `<input-field>` can be of different types, this is managed via the `type` a

### Input field settings

These settings are used to configure your `<input-field>`. **Every `<input-field>` has to start with the `<name>` element.** After the `<name>` element you can configure any of the other settings mentioned above. Beside these settings, they have the followings in common: [label](add-plugin-configuration#label-placeholder-and-help-text), [helpText](add-plugin-configuration#label-placeholder-and-help-text), [defaultValue](add-plugin-configuration#defaultvalue) and [disabled](add-plugin-configuration#disabled).
These settings are used to configure your `<input-field>`. **Every `<input-field>` has to start with the `<name>` element.** After the `<name>` element you can configure any of the other settings mentioned above. Besides these settings, they have the following in common: [label](add-plugin-configuration#label-placeholder-and-help-text), [helpText](add-plugin-configuration#label-placeholder-and-help-text), [defaultValue](add-plugin-configuration#defaultvalue) and [disabled](add-plugin-configuration#disabled).

#### Label, placeholder and help text

Expand All @@ -112,7 +109,7 @@ The settings `<label>`, `<placeholder>` and `<helpText>` are used to label and e

Add the `defaultValue` setting to your `<input-field>` to define a default value for it. This value will be imported into the database on installing and updating the plugin. We use [Symfony\Component\Config\Util\XmlUtils](https://github.com/symfony/config/blob/master/Util/XmlUtils.php#L215) for casting the values into the correct PHP types.

Below you'll find an example how to use this setting.
Below, you'll find an example of how to use this setting.

```html
<input-field type="text">
Expand All @@ -126,7 +123,7 @@ Below you'll find an example how to use this setting.

You can add the `<disabled>` setting to any of your `<input-field>` elements to disable it.

Below you'll find an example how to use this setting.
Below, you'll find an example of how to use this setting.

```html
<input-field>
Expand All @@ -141,7 +138,7 @@ _Please note, `<disabled>` only takes boolean values._

You can add the `<copyable>` setting to your `<input-field>` which are of type `text` or extensions of it. This will add a button at the right, which on click copies the content of your `<input-field>` into the clipboard.

Below you'll find an example how to use this setting.
Below, you'll find an example of how to use this setting.

```html
<input-field>
Expand Down Expand Up @@ -240,7 +237,7 @@ Allows you to edit snippet values within the configuration page. This component

### Supported component types

Please Note: It is impossible to allow every component to the config.xml, due to their complexities. If you can't efficiently resolve your plugin's necessities with, it is probably better to create an own module instead. Therefore, Shopware supports the following components by default (also to be found in the [ConfigValidator class](https://github.com/shopware/platform/blob/729fbf368a065177a17e0fc190334ce02b45f418/src/Core/Framework/App/Validation/ConfigValidator.php#L16)):
Please Note: It is impossible to allow every component to the config.xml, due to their complexities. If you can't efficiently resolve your plugin's necessities with, it is probably better to create an own module instead. Therefore, Shopware supports the following components by default (also to be found in the [ConfigValidator class](https://github.com/shopware/shopware/blob/729fbf368a065177a17e0fc190334ce02b45f418/src/Core/Framework/App/Validation/ConfigValidator.php#L16)):

* sw-entity-single-select
* sw-entity-multi-id-select
Expand All @@ -256,7 +253,7 @@ Now all that's left to do is to present you a working example `config.xml` and s
// <plugin root>/src/Resources/config/config.xml
<?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">
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/shopware/trunk/src/Core/System/SystemConfig/Schema/config.xsd">

<card>
<title>Basic Configuration</title>
Expand Down Expand Up @@ -308,6 +305,10 @@ Now all that's left to do is to present you a working example `config.xml` and s
</config>
```

## Add values to your configuration

After adding your input fields to the `config.xml`, you can add values to your configuration. To do so, navigate from the sidebar to the `Extensions` > `My extensions` > `Apps` tab and click on your plugin's `...` button. Now you can see the `Configuration` tab and fill in the values for your input fields.

## Next steps

Now you've added your own plugin configuration. But how do you actually read which configurations the shop owner used? This will be covered in our guide about [Using the plugin configuration](use-plugin-configuration).
Now you've added your own plugin configuration. But how do you actually read which configurations the shop owner used? This will be covered in our guide about [Using the plugin configuration](use-plugin-configuration).

0 comments on commit a20c59e

Please sign in to comment.