Allow field type to specify a 'process settings' step before saving & loading definitions

Created on 24 November 2013, over 11 years ago
Updated 7 March 2025, 2 months ago

Updated: Comment #0

Problem/Motivation

When a field or field instance gets saved or loaded there's no straight way for the field item class to interact and apply some processing on settings before they are saved or loaded.

A typical case is the image field. In that case some settings, like default image width and height, need processing. Those settings computations are performed now in a inappropriate place, in image_entity_presave(). See image_entity_presave().

Proposed resolution

- Define new processSettings() / processInstanceSettings() method in \Drupal\Core\Field\ConfigFieldItemInterface and let field item implementations to react before saving field/instance settings.
- Provide base implementations that just do "merge default settings"

Call the methods in the places where we currently do the "merge default settings" thing:
- before saving field/instance settings (in Field/FieldInstance::preSave(), once #2020895: Move save() / delete() logic in Field / FieldInstance to [pre|post]Save(), [pre|post]Delete() β†’ finally gets committed),
- and after loading them (FieldInfo::prepareField() / prepareInstance())

- This is not only about configurable fields, base fields will need to run those as well.
Will probably be in EntityManager::getFieldDefinitions() after #2076445: Make sure language codes for original field values always match entity language regardless of field translatability β†’ lands

Remaining tasks

  1. Design the solution.
  2. Patch.
  3. Change existing cases.

User interface changes

N/A

API changes

New method in FieldItemInterface.

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

field system

Created by

πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

Live updates comments and jobs are added and updated live.
  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024