Problem/Motivation
Currently all field enhancer options show up for every field and most are non-applicable to the field type.
Steps to reproduce
Edit resource config and click the Advanced button that displays available enhancers. Acknowledge all enhancers are available when they ideally should rather be dependent on the field type.
Proposed resolution
With this new attribute that would default to empty array, we can match each field type in the resource config form to the allowed types and exclude the enhancer as an option.
Remaining tasks
- Add new attribute to: /Attribute/ResourceFieldEnhancer.php
- Add logic to
JsonapiResourceConfigFormto check for fields allowed in optional definition['field_types'] to filter enhancer options.
User interface changes
As this would be an opt in, no UI changes would be present unless a module sets the attribute in which then plugin definitions would be evaluated for availability to apply.
Testing
Add field_types for example to the UrlLinkEnhancer, clear cache and check a resource type and that enhancer should no longer be an option for fields other than 'link' type.
/**
* Add URL aliases to links.
*/
#[ResourceFieldEnhancer(
id: 'url_link',
label: new TranslatableMarkup('URL for link (link field only)'),
description: new TranslatableMarkup('Use Url for link fields.'),
field_types: ['link'],
)]Issue fork jsonapi_extras-3553150
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
apmsooner commentedComment #3
apmsooner commentedComment #4
apmsooner commentedComment #6
apmsooner commentedComment #7
apmsooner commentedNoting that I didn't touch existing enhancers that ship with the module but it would be my recommendation to apply the 'field_types' attribute to the ones that only make sense with certain types (DateTimeEnhancer, UrlLinkEnhancer, ListFieldEnhancer) for example.