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

Issue fork drupal-2686145

Command icon 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

Deciphered created an issue. See original summary.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

WorldFallz’s picture

Seems 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.

biguzis’s picture

Version: 8.6.x-dev » 8.7.x-dev

Also looking for this in 8.7.x. In my case video height and width is needed when listing video files using fields.

stefan.butura’s picture

stefan.butura’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 10: views-fields-third-party-settings-2686145-10.patch, failed testing. View results

stefan.butura’s picture

stefan.butura’s picture

stefan.butura’s picture

Status: Needs work » Needs review

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mandclu’s picture

The 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.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

klonos’s picture

Coming 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.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mandclu’s picture

Version: 9.5.x-dev » 10.1.x-dev

Moving this to 10.1. It would be amazing if we could get some momentum going on this issue again.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

codebymikey made their first commit to this issue’s fork.

codebymikey’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new6.65 KB

Attached 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.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs upgrade path, +Needs tests

With the new schema change think we will need an upgrade path + tests.

joachim’s picture

Patch 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.

joachim’s picture

Actually, 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

joachim’s picture

I 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.

wim leers’s picture

ressa made their first commit to this issue’s fork.

ressa’s picture

Thanks 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"?

ressa’s picture

Issue summary: View changes

Adding example of a problem this MR fixes in Issue Summary.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

idiaz.roncero’s picture

We now have OOP hooks, meaning that a module can have more than one implementation of hook_field_formatter_third_party_settings_form

We 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.

    $this->moduleHandler->invokeAllWith(
      'field_formatter_third_party_settings_form',
      function (callable $hook, string $module) use (&$settings_form, &$plugin, &$field_definition, &$form, &$form_state) {
        $settings_form[$module] = ($settings_form[$module] ?? []) + ($hook(
          $plugin,
          $field_definition,
          $this->entity->getMode(),
          $form,
          $form_state,
        )) ?? [];
      }
    );

anybody made their first commit to this issue’s fork.

ressa’s picture

Thanks @idiaz.roncero and @anybody! It looks like the MR needs another re-roll ...