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 JsonapiResourceConfigForm to 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'],
)]
Command icon 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

apmsooner created an issue. See original summary.

apmsooner’s picture

Issue summary: View changes
apmsooner’s picture

Issue summary: View changes
apmsooner’s picture

Issue summary: View changes

apmsooner’s picture

Title: Add field_types to field enhancer plugin attributes » Option to limit enhancer options based on 'field_types' plugin attribute.
Assigned: apmsooner » Unassigned
Status: Active » Needs review
apmsooner’s picture

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