New configuration is imported with incorrect order of properties

Created on 30 March 2023, over 1 year ago
Updated 31 May 2023, over 1 year ago

Problem/Motivation

When we import a new config object using drush features:import:all --yes, the configuration that is saved to the database is not properly sorted according to the configuration schema. This can result in additional config diff/exports afterwards to reorder the properties correctly. It would be nice

For example, we have the following config in our feature's config/install/layout_builder_styles.styles.core_text_align_center.yml:

langcode: en
status: true
dependencies: {  }
id: core_text_align_center
label: 'Text align center'
classes: text-align-center
type: component
group: default
block_restrictions:
  - pfg_design_system_card
layout_restrictions: {  }
weight: 0

The config schema for layout_builder_styles.schema.yml defines the following:

layout_builder_styles.style.*:
  type: config_entity
  label: 'Layout builder style config'
  mapping:
    id:
      type: string
      label: 'ID'
    label:
      type: label
      label: 'Label'
    classes:
      type: string
      label: 'Classes'
    type:
      type: string
      label: 'Type'
    group:
      type: string
      label: 'Group'
    block_restrictions:
      type: sequence
      label: 'Block restrictions'
      sequence:
        type: string
    layout_restrictions:
      type: sequence
      label: 'Layout restrictions'
      sequence:
        type: string
    weight:
      type: integer
      label: 'Weight'
    uuid:
      type: string

Note how weight is 2nd to last. When this config gets imported, it gets imported as this:

uuid: 2841c390-cc1b-443f-8d41-1b8eebef969d
langcode: en
status: true
dependencies: {  }
_core:
  default_config_hash: nrpzvVetL3SqzELdWgH-JYdhmjXPT6IN6aCJ7Cu6h7I
id: core_text_align_center
label: 'Text align center'
classes: text-align-center
type: component
group: default
weight: 0
block_restrictions:
  - pfg_design_system_card
layout_restrictions: {  }

Note that weight is now above block_restrictions and layout_restrictions. When this config is saved in the UI, Drupal re-orders it properly. We'd like it to import in the proper order as well.

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States dave reid Nebraska USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @dave reid
  • πŸ‡¨πŸ‡¦Canada nedjo

    Thanks for the report. This appears to result from core changes in [#3230199], see the accompanying change record β†’ . Features needs to sort the way core does. Relevant: #3229250: Add service to sort a config array the same way core does. β†’ . The ideal would be that core exposed a service we could use. Other options seem to include (arranged roughly from most to least attractive):

    • See whether this issue is addressed in Configuration Update Manager (which we already require) and, if so, use a service from that module.
    • If not already fixed in Configuration Update Manager, or if fixed but not yet available in a service, address in that module.
    • Introduce a dependency on Config Split (or some other module that provides a relevant solution). Not so good, as Config Split addresses a distinct set of use cases.
  • πŸ‡¨πŸ‡¦Canada nedjo

    Of course, the ideal would be that core provided something we could rely on, so we don't need to recreate core's (potentially changing) config sort algorithm in various config modules. That could be, for example, an optional boolean $sort argument to a new ConfigInterfaceInterface::save() method or similar.

  • πŸ‡¨πŸ‡¦Canada nedjo

    A possible interim step would be a soft dependency: use the config_split service, if present, to sort config before it's saved.

  • Assigned to dave reid
  • πŸ‡ΊπŸ‡ΈUnited States dave reid Nebraska USA
  • πŸ‡ΊπŸ‡ΈUnited States dave reid Nebraska USA
Production build 0.71.5 2024