Undefined array keys error when using the ExIcon widget

Created on 20 April 2024, 2 months ago

Problem/Motivation

PHP warning errors are displayed if an Ex incon field is set on an entity.

These errors are displayed for each configured icon

  • Warning: Undefined array key "width" in template_preprocess_ex_icon() (line 88 of modules/contrib/ex_icons/ex_icons.module).
  • Warning: Undefined array key "height" in template_preprocess_ex_icon() (line 88 of modules/contrib/ex_icons/ex_icons.module).

Steps to reproduce

  1. Add an icon field to a node type and display it on the form
  2. Create a new node of this type.
  3. Check the log, you will see the warning errors described above.
πŸ› Bug report
Status

Closed: works as designed

Version

1.7

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain frouco

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @frouco
  • Pipeline finished with Failed
    2 months ago
    Total: 149s
    #151824
  • Status changed to Needs work 2 months ago
  • πŸ‡¬πŸ‡§United Kingdom Wongjn

    Hi! Thank you for your report and contribution!

    Can I just double-check you are running 8.x-1.7? It seems dubious that the error message is reporting line 88 when that is outside the template_preprocess_ex_icon() function. Furthermore, we do isset() checks on lines 72–74:

    if (isset($variables['attributes']['width']) xor isset($variables['attributes']['height'])) {
      $numeric_width  = isset($variables['attributes']['width']) && is_numeric($variables['attributes']['width']);
      $numeric_height = isset($variables['attributes']['height']) && is_numeric($variables['attributes']['height']);
    

    So the error shouldn't ever come up.

    Indeed, even in the PHPUnit tests for 8.x-1.7, no such error is surfaced.

    With these two points, I am leaning towards something within your setup specifically. However, if you could provide anymore details to replicate the problem and/or a PHPUnit test to go alongside your MR, that would be most helpful.

  • πŸ‡ͺπŸ‡ΈSpain frouco

    Hi Wongjn

    Yes, Im running 8.x-1.7?

    The issue comes from how are generated the options of the widget, width and height are not set. So the the condition of the line 88 fo the template_preprocess_ex_icon() don't apply.

    The issue can be solved there enforcing the detected size if boot values are empty but i feel that is better set the options of the icons selector correctly. Setting the width and height here and apply them here

  • Pipeline finished with Failed
    2 months ago
    Total: 241s
    #151881
  • πŸ‡¬πŸ‡§United Kingdom Wongjn

    The issue comes from how are generated the options of the widget, width and height are not set. So the the condition of the line 88 in the template_preprocess_ex_icon() don't apply.

    Could I check what the condition on line 88 is please? From what I can see, that line is outside the template_preprocess_ex_icon() function and is a line of the documentation block, unless I am mistaking what the line number is referring to.

    I'd prefer we get to the root of the cause of the warning in template_preprocess_ex_icon() rather than rework render arrays. This is because any code that uses the ex_icon #theme could cause this warning if they don't pass width and height #attributes, so I'd like to fix it at the "origin" point, so to speak.

  • Issue was unassigned.
  • Status changed to Closed: works as designed 2 months ago
  • πŸ‡ͺπŸ‡ΈSpain frouco

    aggg, my mistake

    I did not realise before that I had applied a patch ✨ Allow inline SVG instead of tag Active to the module in the website I was testing.

    Sorry for the noise. I close the MR and this task. Module works correctly

Production build 0.69.0 2024