Problem/Motivation
Field formatter third party settings provided by hook_field_formatter_third_party_settings_form() are missing form the Views UI interface when using Fields.
This can cause problems such as #3523410: Missing Photoswipe Views caption: Drupal core's third party settings formatter missing from Views UI.
Proposed resolution
Add support for Field formatter third party settings to the Views UI interface when using Fields.
Remaining tasks
Test dependency behaviour when one of the third party modules need to be uninstalled.
It should handle the config cleanup without removing the field entirely.
User interface changes
There's now a Use third party settings checkbox for if the field wants third party module integration.
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | 2686145-views-third_party_settings-field-support-28.diff | 6.65 KB | codebymikey |
| #13 | views-fields-third-party-settings-2686145-13.patch | 1.96 KB | stefan.butura |
Issue fork drupal-2686145
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 #8
WorldFallz commentedSeems to be true for video and audio field formatters as well. Don't know if they technically qualify as 'third party' since they're part of the core file field code, but their formatter settings don't show when adding fields the way image field settings do.
Steps to reproduce:
1. add a file field to any content type (i tested with page) and specify either mp3 or mp4 as a valid extension.
2. create a node of that content type with the appropriate type of file.
3. create a view for that content type, add the field, and select the video/audio formatter-- no settings appear.
It looks like it's displaying with the settings for the default display mode. I'll take a look at image fields and try to see what different.
Comment #9
biguzis commentedAlso looking for this in 8.7.x. In my case video height and width is needed when listing video files using fields.
Comment #10
stefan.butura commentedComment #11
stefan.butura commentedComment #13
stefan.butura commentedComment #14
stefan.butura commentedComment #15
stefan.butura commentedComment #19
mandclu commentedThe patch provided in #13 apply cleanly to Drupal 9.2.9 and does allow the the third party setting fields to be added. The settings appear to be saved successfully, as returning to the form shows the previously saved settings.
Unfortunately, within my formatter there's no sign of the third party settings that were saved. I also tried inspecting what's in the $settings array assembled within getFormatterInstance() but it seems that this function is never called as part of the standard rendering process.
Note that #2942661: Sections should have third-party settings added third party settings to Layout Builder Sections by implementing the ThirdPartySettingsInterface and in turn creating methods like getThirdPartySetting, getThirdPartySettings, setThirdPartySetting, etc. Also worth noting that the changes included in this issue included a schema change.
Also marking #3158694: Add and use a ThirdPartySettingsTrait as related, since having a Trait available to implement these kinds of changes would be a big help.
Comment #22
klonosComing here from #2883170: Views support
I confirm that the patch in #13 applies cleanly in 9.4.4, and the formatter settings are shown in the views dialog/form and also properly saved in the view. But as @mandclu also reported, when the view is rendered the formatter is not actually applied.
Comment #24
mandclu commentedMoving this to 10.1. It would be amazing if we could get some momentum going on this issue again.
Comment #28
codebymikey commentedAttached a patch which provides that support for fields.
It should work in a way that ensures that the third_party_settings is entirely optional, keeping the existing views behaviour where possible.
Comment #29
smustgrave commentedWith the new schema change think we will need an upgrade path + tests.
Comment #30
joachim commentedPatch works, but I find it weird UX to have to ticky a box that says 'Use third party setting', especially when the third party settings form is hidden in a details element anyway.
It would be pretty much the same to just show the details element and have it closed by default.
Though I think it would be better UX to have the formatter settings AND the third party settings together in a detail element, so it looks the same as in entity display settings. Although that change would be out of scope of this issue.
Tagging as a contrib project blocker, because this affects any contrib module that offers extra options for field formatters.
Comment #31
joachim commentedActually, the patch doesn't completely work -- I can't remove settings from a field after saving the view:
1. Edit a view, set a third party setting
2. Save it
3. Remove the setting - unselect both the setting AND the 'Use third party setting' checkbox
4. click 'Apply'
5. The settings are still used in the preview output, and editing the field again shows they are back
Comment #32
joachim commentedI think there's some confusion between
$options['third_party_settings']
and
$options['settings']['third_party_settings']
The field formatter system is going to expect third_party_settings to be within its settings, so I think putting them outside of that in the Views config is a mistake, as it just confuses things.
Comment #33
wim leersComment #35
ressaThanks for working on this! The MR works really well and fixes missing Captions settings in PhotoSwipe in Views, #3523410: Missing Photoswipe Views caption: Drupal core's third party settings formatter missing from Views UI.
About the current patch and removing settings, I can only partially replicate it. If I set a value like 'Image alt tag', collapse it by disabling 'Use third party setting' checkbox, and save, the setting does remain, like @joachim commented in #31.
But if I instead first set it to "- None -" and then save, it's no longer active, regardless whether I collapse it or not.
I do think it should be totally disabled (set to "-None -") if the setting is collapsed, by unchecking the 'Use third party setting' checkbox.
Since this can be very hard to debug and understand, and options are mysteriously missing from the Views UI in Contrib modules integration without any clue, resulting in a more or less "dead end", could this issue be considered bumped up to "Major"?
Comment #36
ressaComment #37
ressaAdding example of a problem this MR fixes in Issue Summary.
Comment #39
idiaz.ronceroWe now have OOP hooks, meaning that a module can have more than one implementation of
hook_field_formatter_third_party_settings_formWe need to update this code, as Drupal Core does on EntityViewDisplayEditForm.php::163, to merge all possible settings and avoid the latest hooks from overriding the former.
Comment #41
ressaThanks @idiaz.roncero and @anybody! It looks like the MR needs another re-roll ...