Honor default in schema

Created on 18 October 2024, 6 months ago

Problem/Motivation

We can set a default property to a prop and that should be honored in the form generated by the styleguide.

Steps to reproduce

# Everything in this file is optional. Still, the file needs to exist. Adding
# metadata here will improve the DX when using components.

# This is so your IDE knows about the syntax for fixes and autocomplete.
$schema: https://git.drupalcode.org/project/sdc/-/raw/1.x/src/metadata.schema.json
name: Site Branding
status: stable
group: Blocks

props:
  type: object
  properties:
    site_logo:
      type: string
      title: "Logo"
      description: "URL to the logo file"
      default: "https://pathtoimage.png"
    site_slogan:
      type: string
      title: "Slogan"
      description: "Slogan"
      default: "The Site Slogan is very slogany"
    site_name:
      type: string
      title: "Site Name"
      default: "Site Name"

to generate:

$form['component']['fields'][$field] = [
        '#description' => $settings['description'],
        '#required' => in_array($field, $definition['props']['required'] ?? []),
        '#title' => $settings['title'],
        '#type' => $fapi_map[$settings['type']],
      ];
if (!is_null($settings['default'])) {
  $form['component']['fields'][$field]['#default_value'] = $settings['default'];
}
✨ Feature request
Status

Active

Version

1.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States markie Albuquerque, NM

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