[2.0.0-alpha1] ui_icon_autocomplete must send storable config

Created on 7 August 2024, 8 months ago

Problem/Motivation

ui_icon_autocomplete is submitting an array embeding an object implementing IconDefinitionInterface, generated from the submitted value, which doesn't seem to be easily storable in configuration because I get:

Drupal\Core\Config\UnsupportedDataTypeConfigException: Invalid data type for config element

So, in order to have something storable, the plugins using
ui_icon_autocomplete must alter the submitting value to restore the original submitted value. For example:

  • UiIconWidget::massageFormValues()
  • IconDialog::submitForm()

This is generating 3 issues:

  • we are "reverting" in those methods something we just built in the valueCallback() method of the render element
  • some plugin types doesn't have such a mechanism for altering submitted value. For example, UI Patterns 1.x settings types (from [1.0.0-alpha2] Add UI Patterns integration module Needs work ). We tried to use #element_validate but it seems to be executed before UiIconAutocomplete::valueCallback()
  • the stored config is not unified between plugins, so it will create technical debt and make some data migration complicated

Proposed resolution

I am not 100% sure my understanding of the UnsupportedDataTypeConfigException situation is right, but can we have an unified config storage structure, directly attachable to config entities and directly submitted by ui_icon_autocomplete ?

A new render property can be added to ui_icon_autocomplete as temporary workaround, but the target implementation must be unified and stay simple.

Following Jean's feedbacks, evaluating the complexity trade-off (code we can get rid off VS code we will need to introduce) would be useful.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇫🇷France pdureau Paris

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

Comments & Activities

  • Issue created by @pdureau
  • 🇫🇷France mogtofu33

    There is a chance UnsupportedDataTypeConfigException is because you are missing a schema.yml file for the type and not really a storage problem.

    Still, I agree you should store only icon id and settings.

    But with the current approach it's cleaner to send the object around, advantages are:

    • avoid some dependency injection
    • allow quick interface test instanceof IconDefinitionInterface instead of loading
    • with only full id (iconset_id:icon_id) we introduce multiple explode() for the same thing instead of getIconsetId() or getId(), meaning if we change the separator or the id it needs to be changed everywhere
    • same for getRenderable(), we need to load the icon before when it's not needed with the object

    Because the FormElement is meant to be generic, the rule is to match most implementations, but not all at all cost if it means more code on all other implementations.

    Even more the autocomplete is just one implementation for a picker and should be split in the future to allow other type of selectors.

    Need to check if a simple solution can be found for ui patterns and if not first a property is a mitigating approach before adding code in all other implementations.

  • Assigned to pdureau
  • Status changed to Postponed 8 months ago
  • Issue was unassigned.
  • Status changed to Closed: works as designed 3 months ago
  • 🇫🇷France mogtofu33

    Because this is now in core, we can close.

Production build 0.71.5 2024