From 9c5e980964829c4c1fcbdc98d98bc7a8d7615c5c Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Fri, 15 Nov 2024 15:07:21 +1300 Subject: [PATCH] DOC Document including attributes in formfield schema data --- en/08_Changelogs/6.0.0.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/en/08_Changelogs/6.0.0.md b/en/08_Changelogs/6.0.0.md index acdd6cab..54c3a5d8 100644 --- a/en/08_Changelogs/6.0.0.md +++ b/en/08_Changelogs/6.0.0.md @@ -36,6 +36,7 @@ title: 6.0.0 (unreleased) - [MySQL now defaults to utf8mb4](#mysql-utf8mb4) - [`DBDecimal` default value](#dbdecimal-default-value) - [`RedirectorPage` validation](#redirectorpage-validation) + - [`getSchemaDataDefaults()` now includes attributes](#formfield-schema-data) - [Full list of removed and changed API (by module, alphabetically)](#api-removed-and-changed) ## Features and enhancements @@ -922,6 +923,28 @@ Previously if an invalid default value was provided for a [`DBDecimal`](api:Silv [`RedirectorPage`](api:SilverStripe\CMS\Model\RedirectorPage) now uses the [`Url` constraint](https://symfony.com/doc/current/reference/constraints/Url.html) from `symfony/validator` to validate the `ExternalURL` field. It will no longer add `http://` to the start of URLs for you if you're missing a protocol - instead, a validation error message will be displayed. +### `getSchemaDataDefaults()` now includes attributes {#formfield-schema-data} + +The [`FormField::getSchemaDataDefaults()`](api:SilverStripe\Forms\FormField::getSchemaDataDefaults()) method (and by extension the [`getSchemaData()`](api:SilverStripe\Forms\FormField::getSchemaData()) method) now calls [`getAttributes()`](api:SilverStripe\Forms\FormField::getAttributes()). This was done so that attributes such as `placeholder` can be used in the react components that render form fields. + +In the past it was common to call `getSchemaData()` inside the `getAttributes()` method, so that a form field rendered in an entwine admin context had the data necessary to bootstrap a react component for that field. Doing that now would result in an infinite recursion loop. + +If you were calling `getSchemaData()` in your `getAttributes()` method in a `FormField` subclass include `$SchemaAttributesHtml` in your template instead. For example: + +```diff +-public function getAttributes() +-{ +- $attributes = parent::getAttributes(); +- $attributes['data-schema'] = json_encode($this->getSchemaData()); +- return $attributes; +-} +``` + +```diff +-
++
+``` + ### Full list of removed and changed API (by module, alphabetically) {#api-removed-and-changed}