Problem/Motivation
CustomElementsFieldFormatterBase::getSetting() points into $this->configuration['settings']
But we (by which I mean: any formatters that are not wrapping Core Field formatters) are not using the 'settings' sub-array. So this is both bogus and confusing.
Intent
Not necessarily be perfect, but be harder to inadvertently call the wrong method, for people creating CeFieldFormatters.
Proposed resolution
Alternative 1:
Fix "bogus" by somehow moving the ['settings'] thing into a place where Core Field formatters are still using it, while CustomElementsFieldFormatterBase::getSetting() points into $this->configuration?
If that turns out to be impossible:
Fix "confusing" at least by adding more comments dissuading people from using getSetting(). Note we also have getConfiguration(), which is 'functionally duplicate'; point from one to the other. Maybe note (why) we don't implement PluginSettingsBase, if we haven't yet.
EDIT: This has turned out to be unnecessary, because CustomElementsFieldFormatterBase::getSetting() is not used by Core Field formatters at all. We can therefore just fix the "confusing" part, by removing ['settings'] from the getSetting() code.
Separate but related
Consider implementing a getSetting() equivalent that gets a single setting and returns the default value if it isn't set.
Either merge default config early, and audit the current formatters for any impacet... or (how PluginSettingsBase does it) merge it whenever getSetting() is called.
EDIT: default config is already being merged early. The problem is, we have defaultConfiguration() which is being merged, and defaultSettings() which isn't. This should be fixed by better code comments.
Issue fork custom_elements-3468343
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 #2
roderikComment #3
roderikComment #4
roderikDumping draft comments I jotted down somewhere, to check at the same time. Not fixing for understandability - I will likely be the one to look at this anyway.
Comment #5
roderikBetter comments for myself / later reference (I will be able to find them back):
g/setSetting(s)() + static defaultSettings() are from PluginSettingsInterface
g/setConfiguration() + non-static defaultConfiguration() are from ConfigurableInterface
settingsForm() & settingsSummary() are not in an interface. Core field formatters have them in FormatterInterface but we don't implement that.
settingsForm() is not used anywhere, can be deleted. settingsSummary() we should probably add to CustomElementsFieldFormatterInterface. (We've done the same with static isApplicable() which ia also in FormatterInterface.)
build/validate/submitConfigurationForm() are from PluginFormInterface
There's a Core issue to merge PluginSettingsInterface into ConfigurableInterface (#1764380: Merge PluginSettingsInterface into ConfigurableInterface) but it isn't going anywhere. (If that is ever done, I assume all "*Setting*" names will be deprecated.)
The only reason why we implement PluginSettingsInterface, seems to be that EntityDisplayInterface:getRenderer()'s return value requires it. Otherwise we would not have these duplicate methods.
We could have chosen to not implement ConfigurableInterface instead, but we didn't. (Also PluginSettingsInterface::defaultSettings() is more clunky because static.)
Comment #7
roderik@fago for review, as this is a basic change to your code.
Comment #8
fagoThank you, this seems gresat! This improves things largely and will definitely help to avoid (further) confusion.
Comment #10
fago