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

PHP Warning: Undefined array key "alt" in theme_icon() #6760

Open
jenlampton opened this issue Nov 23, 2024 · 1 comment · May be fixed by backdrop/backdrop#4910
Open

PHP Warning: Undefined array key "alt" in theme_icon() #6760

jenlampton opened this issue Nov 23, 2024 · 1 comment · May be fixed by backdrop/backdrop#4910

Comments

@jenlampton
Copy link
Member

Description of the bug

When running on_the_web module I'm seeing a handful of PHP warnings, one for each icon:

Warning: Undefined array key "alt" in theme_icon() (line 327 of /var/www/html/docroot/core/includes/icon.inc).

Line 327 is as follows:

if (isset($variables['alt']) {

The warning comes because in hook_theme() we are not specifying alt as an allowed value:

  'icon' => array(
      'variables' => array(
        'name' => NULL,
        'path' => NULL,
        'attributes' => array('class' => array()),
        'wrapper_attributes' => array('class' => array()),
      ),
    ),

But when you call the icon() function to display an icon, we are passing the alt in as though it should were defined in hook_theme():

    return theme('icon', array(
      'name' => $icon_name,
      'path' => $icon_path,
      'alt' => $options['alt'],
      'attributes' => $options['attributes'],
    ));

Steps To Reproduce

To reproduce the behavior:

  1. Write some code that calls icon() to render one of the new core icons:
$svg_options = array(
    'alt' => 'alt-test',
    'attributes' => array('class' => array('test-class)),
  );
icon('envelope', $svg_options);
  1. See the warning.

Actual behavior

Warning

Expected behavior

No warning

Additional information

Add any other information that could help, such as:

  • Backdrop CMS version: 1.29.2
  • Web server and its version:
  • PHP version:
  • Database sever (MySQL or MariaDB?) and its version:
  • Operating System and its version:
  • Browser(s) and their versions:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant