Problem/Motivation
The module ships no config/schema directory, so none of the configuration it writes has a schema. On a site with the configuration schema checker on, two things are reported.
Saving /admin/media-pdf-thumbnail/settings/global:
No schema for media_pdf_thumbnail.settings
Saving an entity view display whose image field uses the Media PDF Thumbnail Image formatter:
Schema errors for core.entity_view_display.media.document.media_library with the following errors: ...:content.thumbnail.settings.pdf_file_field missing schema, ...settings.pdf_page missing schema, ... [60 keys on a standard profile]
Every key is reported, image_style, image_link and image_loading included, because with no field.formatter.settings.media_pdf_thumbnail_image_field_formatter entry nothing resolves - not even the three keys the formatter only inherits from the image formatter it extends.
Steps to reproduce
Drupal 11.4.6, media_pdf_thumbnail 7.0.0, standard profile.
- Install the module.
- Save the global settings form. -> first message.
- Set
thumbnailon a media view display to the Media PDF Thumbnail Image formatter and save. -> second message.
drush config:inspect --only-error shows the same thing: media_pdf_thumbnail.settings No schema, and 60 missing schema keys under the display.
Proposed resolution
config/schema/media_pdf_thumbnail.schema.yml covering the two config objects. media_pdf_thumbnail.settings is a plain two-key config_object. The formatter entry is type: field.formatter.settings.image plus its own keys, the way core's field.formatter.settings.media_thumbnail extends its parent.
The per-bundle keys cannot go in the YAML: getDefaultSettings() seeds ten settings per media bundle, keyed <bundleId>_page, <bundleId>_field and so on, and config schema has no wildcard for keys inside a mapping. hook_config_schema_info_alter() adds them at runtime, the way ckeditor5_config_schema_info_alter() does for its own plugin-named keys.
Because the typed configuration definitions are cached with no cache tag, hook_ENTITY_TYPE_insert() / hook_ENTITY_TYPE_delete() on media_type clear them, so a bundle added later is covered in the same request - a configuration import that creates a media type and a display together, for instance. Without that, the schema only lists the bundles that existed when the definitions were last cached.
Remaining tasks
Six settings hold a different PHP type depending on how the value got there, and SchemaCheckTrait::checkValue() compares types strictly, so naming any one type makes the others an error. They are typed ignore:
| key | getDefaultSettings() | after a form save |
|---|---|---|
pdf_page |
1 (integer) |
'2' (string) |
image_link_attributes_download |
'' (string) |
'1' / 0 |
use_cron |
'' (string) |
'1' / 0 |
<bundle>_enable |
'' (string) |
'1' / 0 |
<bundle>_use_cron |
'' (string) |
'1' / 0 |
<bundle>_attributes_download |
'' (string) |
'1' / 0 |
A checked checkbox writes the string '1' and one that is not checked the integer 0, while the defaults seed an empty string; pdf_page is seeded as an integer and comes back from its number element as a string. <bundle>_page is consistent - always a string - and is typed properly.
The clean fix is to normalize what the plugin and the form write and add a hook_update_N rewriting the displays and views already saved, after which those keys can be typed properly. That is a behaviour change and is left for a follow-up; ignore has precedent in core outside tests, in layout_builder.schema.yml and field.schema.yml.
User interface changes
None.
API changes
None.
Data model changes
Adds a configuration schema. No stored configuration changes.
Issue fork media_pdf_thumbnail-3620862
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
luissousa21 commentedMR !16, against 7.0.x.
The schema itself is two entries.
media_pdf_thumbnail.settingsis a plainconfig_object. The formatter istype: field.formatter.settings.imageplus its own keys, soimage_style,image_linkandimage_loadingare inherited rather than repeated.TypedConfigManagercaches its definitions with no cache tag, so the schema only lists the bundles that existed when that cache was built - the twomedia_typehooks clear it, otherwise a configuration import that adds a media type and a display in one request still reportsmissing schema.Verified on Drupal 11.4.6 / PHP 8.3 with 7.0.0. After the change
drush config:inspect --only-errorreports nothing for either object. phpcs, phpstan, eslint and cspell are clean for the files this touches; the three phpstan errors, one phpcs warning and three eslint errors left in the project are pre-existing in files this does not touch.Comment #6
sgostanyan commentedComment #8
luissousa21 commentedThanks for reviewing the issue @sgostanyan! Would it be possible to add me in the contribution record? Thanks!
Comment #9
sgostanyan commented