Problem/Motivation
The logic which decides whether to display the field plugin (formatter/widget) settings edit button currently tests whether there is any settings summary text to display. If so, the summary text and the edit button are displayed.
However, if there is no summary text, the edit button will not be shown, even if settings are available for the plugin. This is a bug; the decision to show the edit-button should depend on whether settings are available.
This matters because hook_field_formatter_settings_form_alter() allows modules to add extra settings to formatters which don't already have settings. Meanwhile, the summary text for the extra settings needs to be set in hook_field_formatter_settings_summary_alter(), but there is no way to guarantee that summary text is being provided by that hook. (Likewise for the widget alter hooks.)
When a contrib module extends a formatter's settings, it doesn't always make sense to add any summary text, because when several modules extend formatter settings, the settings summaries can become overcrowded.
Steps to reproduce this bug
The problem isn't obvious when looking just at core; most (all?) of the core field formatters which have settings produce a summary message in all cases.
To reproduce this, you'll need a module that provides extra field plugin settings. I suggest using Field formatter class, which has a D8 version. It provides an extra setting to all field formatters, to add HTML classes to the display output. If an extra class is specified, it will be indicated in the settings summary message. (I've deliberately disabled the "no class" summary message in the latest 8.x-1.x-dev.)
Proposed Resolution
Refactor Drupal\field_ui\DisplayOverviewBase::buildFieldRow() so that the edit-button is shown whenever there are plugin settings available.
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
#42 | 2029857-41.patch | 3.11 KB | plopesc |
#42 | 2029857-41-test-only.patch | 2.21 KB | plopesc |
#37 | 2029857-37.patch | 3.5 KB | plopesc |
#37 | 2029857-37-plugin-definition.patch | 3.35 KB | plopesc |
#37 | 2029857-37-test-only.patch | 2.52 KB | plopesc |
Comments
Comment #1
andrewmacpherson CreditAttribution: andrewmacpherson commentedI had a stab at fixing this. The attached patch seems to work okay, lets see if the tests are green.
The patch moves some code which generates the formatter settings form, outside of the if/else block, so that it gets generated whether we are in edit mode or not. Then separate checks are done to determine whether to display the summary and edit button respectivley.
Note that in order to test this, you'll need a module that provides extra field formatter settings. I suggest using the Field formatter class, which has an 8.x version. (I've deliberately disabled the "no class" summary message in the latest 8.x-1.x-dev.)
Comment #2
swentel CreditAttribution: swentel commentedMakes sense to me. Tagging for a usability review.
Comment #3
andrewmacpherson CreditAttribution: andrewmacpherson commentedAdding the usability tag ;-)
Comment #4
andrewmacpherson CreditAttribution: andrewmacpherson commented#1: field_formatter_settings_edit-button-2029857-1.patch queued for re-testing.
Comment #5.0
(not verified) CreditAttribution: commentedadding the screenshot
Comment #6
andrewmacpherson CreditAttribution: andrewmacpherson commentedAlso applies to widget settings, since form modes were committed in #2014821: Introduce form modes UI and their configuration entity.
Updated title and issue summary.
Comment #7
andrewmacpherson CreditAttribution: andrewmacpherson commentedThis is a far simpler patch :-)
Comment #7.0
andrewmacpherson CreditAttribution: andrewmacpherson commentedBug affects field widgets as well as plugins since form modes were introduced. Added steps to reproduce.
Comment #8
yched CreditAttribution: yched commentedYou could simply check if ($plugin->getSettings())
Other than that, why not. Please check whether the phpdoc for the summary() methods in the widgets an formatters interfacesneed to be updated ?
Comment #9
andrewmacpherson CreditAttribution: andrewmacpherson commentedOkay, this patch uses ($plugin->getSettings())
Can we leave checking documentation to a separate issue?
Comment #10
yched CreditAttribution: yched commentedNot really :-). If the changes here make existing docs incorrect/obsolete, they should be updated accordingly in the patch too.
I.m only talking about checking the existing docs for settingsSummary() and settingsForm() in FormatterInterface because they might mention the current behavior (button only if summary not empty). Maybe they don't and everything's fine, it's just that I'm away from my coding env and checking the issue queues with my phone, so it's not easy for me to check the code myself :-) - but TBH I'd be surprised if the current behavior isn't docimented anywhere.
Comment #11
swentel CreditAttribution: swentel commentedYeah, there was a mention in the interface.
Comment #12
yched CreditAttribution: yched commentedThanks @swentel, forgot about this one.
Right, should be good then :-)
Comment #13
alexpottWe should have a test for this so we don't break this during future refactorings.
Comment #14
swentel CreditAttribution: swentel commentedGoing to raise this to major. The settings form also doesn't work anymore if you move a field from hidden to content, you can't toggle the settings button as long as you haven't saved the the display.
Comment #15
swentel CreditAttribution: swentel commentedRefocusing, opened #2084371: Settings form does not work when moving from hidden to content
Comment #16
swentel CreditAttribution: swentel commentedNow with tests
Comment #17
swentel CreditAttribution: swentel commentedHmm the test is actually, wrong, one second.
Comment #18
swentel CreditAttribution: swentel commentedFix
Comment #20
swentel CreditAttribution: swentel commentedThis is green.
Comment #21
yched CreditAttribution: yched commentedLooks good.
Comment #22
alexpottPatch no longer applies.
Comment #23
swentel CreditAttribution: swentel commentedrerolled
Comment #24
swentel CreditAttribution: swentel commentedOk, this should be better, too lazy for interdiff though.
Comment #25
swentel CreditAttribution: swentel commentedDear me
Comment #26
Hydra CreditAttribution: Hydra commented#25: field_plugin_settings_edit-button-2029857-25.patch queued for re-testing.
Comment #28
swentel CreditAttribution: swentel commentedThe function signature for viewElements was changed.
Comment #29
alexpott#28: 2029857-28.patch queued for re-testing.
Comment #31
swentel CreditAttribution: swentel commentedAfter the big Field renames ...
Comment #32
alexpottCommitted 069902e and pushed to 8.x. Thanks!
Added missing @file doc block during commit
Comment #33
plopescHello
I've been testing this and I found an annoying behavior with patch committed in #31.
Problem is that it is checking this:
Plugin can have settings, but not form settings. In that case, the settings button is shown, but once clicked, nothing happens.
It should check that there are an available setting form for that plugin instead of the existence of a settings array.
Steps to reproduce:
Attaching patch that checks if the plugin has a config form instead of settings array.
Regards.
Comment #34
yched CreditAttribution: yched commentedThat's weird. When you select a different formatter, the whole row should be updated, and the presence of the "settings" button re-evaluated against the new formatter.
Comment #35
plopescChanging status. Let's see testbot...
Comment #36
Bojhan CreditAttribution: Bojhan commentedThis seems to be just a bug.
Comment #36.0
Bojhan CreditAttribution: Bojhan commentedminor edit, plugin instead of formatter.
Comment #37
plopescHello
I was talking yesterday with yched about this issue, and he suggested me to display or not edit plugin link depending on
getPluginDefinition()
provides plugin settings or not. It works unlesshook_field_formatter_settings_form_alter()
adds some form elements to a plugin that does not provide settings. In that case, edit plugin link is not displayed and you can't edit settings provided byhook_field_formatter_settings_form_alter()
.Attaching 3 files, test-only, plugin-definition approach and settings form approach.
Any thoughts?
Regards.
Comment #38
yched CreditAttribution: yched commentedCurrently, a module that implements hook_field_formatter_settings_form_alter() typically also alters the formatter definition to add the corresponding settings - or else the form inputs wouldn't get saved.
This might change after #2005434: Let 3rd party modules store extra configuration in EntityDisplay / #2136197: Move field/instance/widget/formatter settings out of annotation / plugin definition, but let's see when those happen.
2029857-37-plugin-definition.patch simply fixes the implementation of the approach committed earlier, I 'd rather stick with that for now ?
We should add a comment explaining why $plugin->getSettings() isn't appropriate here.
Comment #42
plopescOK, let's see if now we have it :)
Now checks
getPluginDefinition()
, created a new field_test formatter without any setting to gives test support.Regards.
Comment #44
yched CreditAttribution: yched commentedLooks good. Thanks !
Comment #45
alexpottCommitted bf3ac2f and pushed to 8.x. Thanks!
Fixed the following during commit.