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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andrewmacpherson’s picture

Status: Active » Needs review
FileSize
2.48 KB

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

swentel’s picture

Makes sense to me. Tagging for a usability review.

andrewmacpherson’s picture

Issue tags: +Needs usability review

Adding the usability tag ;-)

andrewmacpherson’s picture

Status: Needs review » Needs work
Issue tags: +Needs usability review, +Field API

The last submitted patch, field_formatter_settings_edit-button-2029857-1.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

adding the screenshot

andrewmacpherson’s picture

Title: Field formatter settings edit button doesn't show unless there is a settings summary » Field plugin settings edit button doesn't show unless there is a settings summary

Also applies to widget settings, since form modes were committed in #2014821: Introduce form modes UI and their configuration entity.

Updated title and issue summary.

andrewmacpherson’s picture

Status: Needs work » Needs review
FileSize
848 bytes

This is a far simpler patch :-)

andrewmacpherson’s picture

Issue summary: View changes

Bug affects field widgets as well as plugins since form modes were introduced. Added steps to reproduce.

yched’s picture

You 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 ?

andrewmacpherson’s picture

Okay, this patch uses ($plugin->getSettings())

Can we leave checking documentation to a separate issue?

yched’s picture

Can we leave checking documentation to a separate issue?

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

swentel’s picture

Yeah, there was a mention in the interface.

yched’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @swentel, forgot about this one.
Right, should be good then :-)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

We should have a test for this so we don't break this during future refactorings.

swentel’s picture

Title: Field plugin settings edit button doesn't show unless there is a settings summary » Field plugin settings edit button doesn't show unless there is a settings summary or when moving a field from hidden to content
Priority: Normal » Major

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

swentel’s picture

Title: Field plugin settings edit button doesn't show unless there is a settings summary or when moving a field from hidden to content » Field plugin settings edit button doesn't show unless there is a settings summary
Priority: Major » Normal
swentel’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
3.34 KB
5.94 KB

Now with tests

swentel’s picture

Status: Needs review » Needs work

Hmm the test is actually, wrong, one second.

swentel’s picture

Status: Needs work » Needs review
FileSize
3.33 KB
5.93 KB

Fix

Status: Needs review » Needs work

The last submitted patch, field_plugin_settings_edit-button-2029857-18.patch, failed testing.

swentel’s picture

Status: Needs work » Needs review
FileSize
913 bytes
5.92 KB

This is green.

yched’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Patch no longer applies.

swentel’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
5.93 KB

rerolled

swentel’s picture

Ok, this should be better, too lazy for interdiff though.

swentel’s picture

Hydra’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs usability review, +Field API, +Needs reroll

The last submitted patch, field_plugin_settings_edit-button-2029857-25.patch, failed testing.

swentel’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
FileSize
846 bytes
5.9 KB

The function signature for viewElements was changed.

alexpott’s picture

#28: 2029857-28.patch queued for re-testing.

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs usability review, +Field API

The last submitted patch, 2029857-28.patch, failed testing.

swentel’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
1.16 KB
5.88 KB

After the big Field renames ...

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 069902e and pushed to 8.x. Thanks!

Added missing @file doc block during commit

--- a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldEmptySettingFormatter.php
+++ b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldEmptySettingFormatter.php
@@ -1,5 +1,10 @@
 <?php

+/**
+ * @file
+ * Contains \Drupal\field_test\Plugin\field\formatter\TestFieldEmptySettingFormatter
+ */
+
 namespace Drupal\field_test\Plugin\field\formatter;
plopesc’s picture

Status: Fixed » Needs work
FileSize
3.02 KB
2.04 KB
13.66 KB
22.58 KB

Hello

I've been testing this and I found an annoying behavior with patch committed in #31.

Problem is that it is checking this:

+++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php
@@ -355,6 +355,8 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En
+        }
+        if ($plugin->getSettings()) {
           $field_row['settings_edit'] = $base_button + array(

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:

  1. Create a field which haa more than one available formatter, one of them ithout settings form (IE: Number float field)
  2. Select the formatter which has setings form (IE: Default formatter) and configure its settings
    formatter_settings.png
  3. Select the formatter which does not have configuration form (IE: Unformatted). After the AJAX, you'll see something like this:
    formatter_unwanted_settings.png
  4. Click on the configuration button, and check that nothing happens

Attaching patch that checks if the plugin has a config form instead of settings array.

Regards.

yched’s picture

That'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.

plopesc’s picture

Status: Needs work » Needs review

Changing status. Let's see testbot...

Bojhan’s picture

Issue tags: -Needs usability review

This seems to be just a bug.

Bojhan’s picture

Issue summary: View changes

minor edit, plugin instead of formatter.

plopesc’s picture

Hello

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 unless hook_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 by hook_field_formatter_settings_form_alter().

Attaching 3 files, test-only, plugin-definition approach and settings form approach.

Any thoughts?

Regards.

yched’s picture

It works unless
hook_field_formatter_settings_form_alter() adds some form elements to a
plugin that does not provide settings

Currently, 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.

The last submitted patch, 37: 2029857-37-test-only.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 37: 2029857-37.patch, failed testing.

The last submitted patch, 37: 2029857-37-plugin-definition.patch, failed testing.

plopesc’s picture

Status: Needs work » Needs review
FileSize
2.21 KB
3.11 KB

OK, 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.

The last submitted patch, 42: 2029857-41-test-only.patch, failed testing.

yched’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Thanks !

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed bf3ac2f and pushed to 8.x. Thanks!

Fixed the following during commit.

git diff ./core/
diff --git a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldFormatter/TestFieldNoSettingsFormatter.php b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/F
index 2eb76e0..1d3d150 100644
--- a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldFormatter/TestFieldNoSettingsFormatter.php
+++ b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldFormatter/TestFieldNoSettingsFormatter.php
@@ -3,7 +3,7 @@
 /**
  * @file
  *
- * Contains \Drupal\field_test\Plugin\field\formatter\TestFieldNoSettingsFormatter.
+ * Contains \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldNoSettingsFormatter.
  */
 namespace Drupal\field_test\Plugin\Field\FieldFormatter;

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.