Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
With PHP 7.1+, lines 54 and 60 of special_menu_items.module are throwing an error: '[] operator not supported for strings'.
Comment | File | Size | Author |
---|---|---|---|
#5 | 3024643-5.patch | 1.19 KB | mark_fullmer |
#5 | 3024643-4-5.interdiff.txt | 736 bytes | mark_fullmer |
Comments
Comment #2
jmcerda CreditAttribution: jmcerda as a volunteer commentedComment #3
jmcerda CreditAttribution: jmcerda as a volunteer commentedComment #4
DamienMcKennaI suspect this might be caused by another module or even the theme. It's common for people to make $variables['options']['attributes']['class'] a string when it really needs to be an array.
Please try this.
Comment #5
mark_fullmerAs described in the comment, the patch in #4 attempts to fix the problem of a site which is adding a class attribute as a string rather than an array.
However, the problem remains for PHP 7.1 and above for this line:
$variables['options']['attributes']['tabindex'][] = '0';
This line is still applying an empty index operator to a string, which is disallowed per https://www.php.net/manual/en/migration71.incompatible.php
An additional problem with this line is that it will override any
tabindex
values sent to it by thel()
function. There are valid scenarios where the<nolink>
render should not be focusable.The design of adding a tabindex to a
span
tag is understandable, so that it behaves similar to a link. However, this behavior should be the fallback, not the the only possibility.We have a use case, for example, where we have adjacent links that point to the same destination, so for accessibility reasons, we want to set the
tabindex
to-1
, as shown below:In short, this module should respect the tabindex value, if it is already provided, and if not, it can fallback to a
0
value that is not cast to array.The attached patch includes the fix in #4 (see interdiff) and additionally fixes the
tabindex
fallback, while wrapping it in a conditional that will respect an existing value.Comment #6
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedThanks for reporting this.
Regarding the
class
attribute: This is not a bug of this module. Class must be an array as specified in the core documentation oftheme_link
function: https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_link/7.xI prefer not to "babysit" other modules/themes which does not follow documentation.
However I will take a look at the second problem (
tabindex
), which seems valid.Comment #8
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedCommitted and fixed the problem with
tabindex
. Thanks all!I plan to roll-out a new release with few fixes from today soon.