[1.0.0-alpha3] Make Settings JSON schema compliant

Created on 20 August 2024, 8 months ago
Updated 29 August 2024, 7 months ago

Problem/Motivation

In Icon Packs plugin definition, settings property is expected to have a JSON Schema value.

However, there a some invalid JSON schema in https://git.drupalcode.org/project/ui_icons/-/tree/1.0.x/modules/ui_icon...

Examples

suffix and required doesn't exist:

    height:
      title: "Height"
      description: "Set a height for this icon."
      type: "integer"
      default: 32
      required: true
      suffix: "px"

type is missing:

    title:
      title: "Title"
      description: "Set a title on hover for this icon."

step doesn't exist, maybe multipleOf can do the job: https://json-schema.org/understanding-json-schema/reference/numeric#mult...

   stroke_width:
      title: "Stroke width"
      description: "Set a stroke width for this icon."
      type: "number"
      default: 1.5
      step: 0.1

We may also need to do some change https://git.drupalcode.org/project/ui_icons/-/blob/1.0.x/src/Form/IconEx... which is using those unexpected properties and others Form API:

      case 'color':
        return 'color';
    $numberProperties = ['min', 'max', 'step'];

Proposed resolution

It seems the settings are a mix between JSON Schema & Form API, we need to pick one and only one.

Proposal 1: JSON Schema

Fix the examples and IconExtractorSettingsForm

Mateu has already did a JSON Schema to Forms implementation: https://github.com/e0ipso/schema-forms-php which is complicated because he is dealing with all 6 JSON types: string, boolean, number, integer, array & object.

In order to keep thing simple, we can limit ourselves to the 4 scalars: string, boolean, number & integer, but implement them fully.

It is possible to take inspiration from the UI Patterns 2 source plugins:

Proposal 2: Form API

This is the simpler proposal to implement (just a straightforward mapping from YAML to PHP), but the less dev friendly (Form API is a Drupalism) and not future ready (usage of JSON schema in SDC seems to show the way).

But we can discuss about this way.

Fix the examples and IconExtractorSettingsForm.

📌 Task
Status

Fixed

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024