Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow-up: How to deal with existing <title> elements in SVG (icons) in function image_add_svg_attributes() #6731

Open
indigoxela opened this issue Oct 14, 2024 · 0 comments

Comments

@indigoxela
Copy link
Member

indigoxela commented Oct 14, 2024

Description of the task

In a code comment on backdrop/backdrop#4797 a request has been made to take care of existing titles in SVG elements:

I realize that this is not part of the scope here, but is this whole code here making an assumption that the given svg does not have an existing <title>? 🤔

^^ raised by @klonos

This concern's valid - given, this function is available for other SVG types, not only icons (which usually don't have any title child elements).

But as it is/was out of scope in #6613, and desired behavior's still to determine - and to not block the bugfix - we decided to discuss this in a follow-up.

Additional information

  • Function image_add_svg_attributes() has been added in Backdrop 1.28.0, core/includes/image.inc
  • Its current purpose and only usage is to deal with alt attributes in SVG icons, core/includes/icon.inc
  • But the function name suggests, that there could be additional use cases

To have something to play with:

$svg_content = '<svg width="400" height="400" version="1.1" viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg"><rect width="400" height="400" fill="#93a7ac"/></svg>';

And now with a title child:

$svg_content = '<svg width="400" height="400" version="1.1" viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg"><title>Hello</title><rect width="400" height="400" fill="#93a7ac"/></svg>';

Now, if calling image_add_svg_attributes() like that, with alt set to an empty string - what should happen?
And what should happen, if it's a non-empty string?

$attributes = array('alt' => 'Hello');
$foo = image_add_svg_attributes($svg_content, $attributes);

And for completeness: what are the use-cases to deal with?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant