Plugin options arrays with key=>pair values aren't overriding the default ones

Hello,

I think I’m running into a similar issue than this one: [Cms] Plugin options arrays aren't overriding the default ones · Issue #1088 · getkirby/kirby · GitHub.
The difference is, instead of an array of values:

'myarray' => [ 'Option_A', 'Option_B', 'Option_C', 'Option_D', 'Option_E']

…I’m trying to setup an array of key => value pairs.

Kirby::plugin('abc/xyz', [
    'options' => [
      'myarray' => [
        'Option_A' => 'Option A',
        'Option_B' => 'Option B',
        'Option_C' => 'Option C',
        'Option_D' => 'Option D',
        'Option_E' => 'Option E',
      ]
    ]
]);

I’m using it to define the options of a select field:

fields:
  platform:
    type: select
    options:
      type: query
      query: kirby.option('abc.xyz.myarray')

Unfortunately, when I try to override the value of myarray within the project’s config.php like this:

'abc.xyz.myarray' => [
        'Option_C' => 'Option C renamed',
        'Option_D' => 'Option D',
        'Option_Z' => 'Option Z',
  ]

…then option('abc.xyz.myarray') returns the combination of the original and the custom config, instead of overwriting it:

[
    'Option_A' => 'Option A', // should be removed
    'Option_B' => 'Option B', // should be removed
    'Option_C' => 'Option C renamed', // ok, value changed
    'Option_D' => 'Option D', // ok, kept
    'Option_E' => 'Option E', // should be removed
    'Option_Z' => 'Option Z', // ok, added
]

Am I missing something?

Config options (default plugin options and config options) are merged recursively, so you cannot override that options array the way you are trying to do it.

What you can do to prevent the recursive merge, is to define your options in config.php like this:

	'abc'                         => [
		'xyz' => [
			'myarray' => [
				'Option_C' => 'Option C renamed',
				'Option_D' => 'Option D',
				'Option_Z' => 'Option Z',
			],
		],
	],
1 Like

Thank you so much Sonja !