Allow choice of attributes to process

Created on 16 May 2023, over 1 year ago
Updated 3 November 2023, 11 months ago

Problem/Motivation

My use case for this module is to convert inline image paths in WYSIWYG fields to absolute URLs – for Drupal's JSON:API output that's consumed by a front-end that needs those image paths to be absolute.

I don't want to transform relative paths in <a> tag href attributes, though.

Proposed resolution

Allow the user to choose which attributes to process and which to skip.

User interface changes

A filter settings form (with choice of each HTML attribute as a boolean checkbox) is added to any Text format that enables the rel_to_abs input filter.

Data model changes

The settings array is saved to the site config. The choice is for which attributes are to be skipped instead of which are enabled partly for backward compatibility – so that the module operates as previously (on "all" attributes) if the user makes no choice.

The forthcoming patch also uses the expanded set of attributes that is used in \Drupal\Component\Utility\Html::$urlAttributes (plus background as this module was already doing.

$uriAttributes = ['href', 'poster', 'src', 'cite', 'data', 'action', 'formaction', 'srcset', 'about', 'background'];

Remaining tasks

  • Try patching and using without re-saving the settings form
  • Add tests
✨ Feature request
Status

Needs review

Version

2.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jeffschuler Boulder, Colorado

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024