Problem/Motivation
I am currently playing around with the computed_field module in combination with ui_patterns. Unfortunately, computed fields are not able to use the same source plugins as fields with a storage do.
I think the problem is in Drupal\ui_patterns\Plugin\Derivative\EntityFieldSourceDeriverBase::getEntityBundleFieldsMetadata(), where the following condition is implemented:
if (!array_key_exists($field_name, $field_storage_definitions)) {
continue;
}
Due to the fact, that computed fields do not have a storage, those fields are always skipped. So I altered that condition in my local installation to the following (see the additional check, if the field is computed):
if (!array_key_exists($field_name, $field_storage_definitions) && !$field_definition->isComputed()) {
continue;
}
This allows computed fields to be selected e.g. with the Add data from field source plugin or use the Add field formatter source directly. Additionally I did not see any errors or problems with this approach yet, while playing around with it.
Steps to reproduce
- NOTE: I think this should be reproducable with any computed field, but I am mentioning
computed_fieldmodule here, because I realized the issue with a computed field defined by that module's plugin system - Install
computed_fieldandui_patternsmodules - Add a computed field to any entity bundle via basic
computed_fieldplugin - Head over to
Manage displayof the entity bundle and apply theComponent per item (UI Patterns)formatter to the computed field and use any component that provides a slot - Open up the drop button of the slot form and see there is no
Add field formatterbutton - Use the drop button of the slot form and select
Add data from field- the computed field will not be available in theFieldselect element - Manually apply the above proposed code change, clear all caches and try again - both mentioned source plugins should be selectable now and should work as expected with the computed field
Proposed resolution
- Review proposed code change, if there may be any negative side-effects - if so, find another solution to support computed fields with
Component per item (UI Patterns)formatter
Remaining tasks
- Create an issue fork and MR to fix this issue
User interface changes
n/a
API changes
n/a
Data model changes
n/a
Issue fork ui_patterns-3466359
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
hctomFixed typo in module name
Comment #3
pdureau commentedIt is a new feature, so let's check that in beta2
Comment #5
hctomOnly added the proposed fix as issue fork / MR, so we have a starting point and it may be used for patching the module.
Comment #6
pdureau commentedComment #7
pdureau commentedDisclaimer: This issue is not about computed field properties (in Drupal Core, found in: DateRangeItem, DateTimeItem, EntityReferenceItem, FileUriItem) but computed fields.
Unfortunately, AFAIK, there are no entity type with computed fields in Drupal Core.
So, considering the change is very light (a single line) and looks safe, I will merge it.
Comment #9
pdureau commentedComment #10
pdureau commented