TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given

Created on 24 May 2023, about 1 year ago
Updated 18 November 2023, 7 months ago

Problem/Motivation

After upgrade from PHP 7.4 to PHP 8.1, we get this error when visit: /admin/appearance

TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given en system_themes_page() (línea 239 de /PATH_OF_DRUPAL/modules/system/system.admin.inc).

Steps to reproduce

Drupal 7.97
PHP 8.1

Proposed resolution

The problem is in this line:
$theme_group_titles = array(
'enabled' => format_plural(count($theme_groups['enabled']), 'Enabled theme', 'Enabled themes'),
);
So, it seems that $theme_groups['enabled'] is empty.
Making a control like is_array does not work.

🐛 Bug report
Status

Postponed: needs info

Version

7.0 ⚰️

Component
System 

Last updated 1 day ago

No maintainer
Created by

🇪🇸Spain JOINSO Sabadell

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

Comments & Activities

  • Issue created by @JOINSO
  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    2,151 pass
  • @sakthi_dev opened merge request.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India sakthi_dev

    Please review.

  • 🇪🇸Spain JOINSO Sabadell

    Hi!
    I add more info:
    Active themes:
    MY_THEME (a subtheme of Adaptive Themes(AT))
    AT Admin 7.x-3.5
    AT Core 7.x-3.5
    Bartik 7.97
    Seven 7.97
    If try to go to:
    /admin/appearance/settings/bartik
    I get an access denied,
    but now if I go to /admin/appearance/settings/seven

  • 🇪🇸Spain JOINSO Sabadell

    More info.
    Making some debug I get this:
    [26-May-2023 07:43:11 Europe/Paris] Theme:stdClass Object
    (
    [uri] => sites/all/themes/adaptivetheme/at_admin/adaptivetheme_admin.info
    [filename] => sites/all/themes/adaptivetheme/at_admin/adaptivetheme_admin.info
    [name] => adaptivetheme_admin
    [status] => 0
    )

    [26-May-2023 07:43:11 Europe/Paris] Theme:stdClass Object
    (
    [uri] => sites/all/themes/adaptivetheme/at_core/adaptivetheme.info
    [filename] => sites/all/themes/adaptivetheme/at_core/adaptivetheme.info
    [name] => adaptivetheme
    [status] => 0
    )

    [26-May-2023 07:43:11 Europe/Paris] Theme:stdClass Object
    (
    [uri] => sites/all/themes/adaptivetheme/at_subtheme/adaptivetheme_subtheme.info
    [filename] => sites/all/themes/adaptivetheme/at_subtheme/adaptivetheme_subtheme.info
    [name] => adaptivetheme_subtheme
    [status] => 0
    )

    [26-May-2023 07:43:11 Europe/Paris] Theme:stdClass Object
    (
    [uri] => themes/bartik/bartik.info
    [filename] => themes/bartik/bartik.info
    [name] => bartik
    [status] => 0
    )

    [26-May-2023 07:43:11 Europe/Paris] Theme:stdClass Object
    (
    [uri] => sites/all/themes/f4r/f4r.info
    [filename] => sites/all/themes/f4r/f4r.info
    [name] => f4r
    [status] => 0
    )

    [26-May-2023 07:43:11 Europe/Paris] Theme:stdClass Object
    (
    [uri] => themes/garland/garland.info
    [filename] => themes/garland/garland.info
    [name] => garland
    [status] => 0
    )
    [26-May-2023 07:43:11 Europe/Paris] Theme:stdClass Object
    (
    [uri] => themes/seven/seven.info
    [filename] => themes/seven/seven.info
    [name] => seven
    [status] => 0
    )

    [26-May-2023 07:43:11 Europe/Paris] Theme:stdClass Object
    (
    [uri] => themes/stark/stark.info
    [filename] => themes/stark/stark.info
    [name] => stark
    [status] => 0
    )

    So, all my themes are disabled, and this:

    $theme_group_titles = array(
    'enabled' => format_plural(count($theme_groups['enabled']), 'Enabled theme', 'Enabled themes'),
    );

    Becomes not safe.
    So, I am going to study how to enable themes....
    A suggestion to improve this:
    if all themes are disabled, does not let the admin page fails.

  • 🇪🇸Spain JOINSO Sabadell

    And more info:
    In modules/system/system.module:
    function function system_rebuild_theme_data() {
    ....
    system_get_files_database($themes, 'theme');
    ...
    }
    I debug data before and after calling "system_get_files_database", and I get this in PHP 7.4:

    [26-May-2023 08:44:06 Europe/Paris] Before Theme (adaptivetheme) :
    [26-May-2023 08:44:06 Europe/Paris] Before Theme (adaptivetheme_admin) :
    [26-May-2023 08:44:07 Europe/Paris] Before Theme (adaptivetheme_subtheme) :
    [26-May-2023 08:44:07 Europe/Paris] Before Theme (bartik) :
    [26-May-2023 08:44:07 Europe/Paris] Before Theme (f4r) :
    [26-May-2023 08:44:07 Europe/Paris] Before Theme (garland) :
    [26-May-2023 08:44:07 Europe/Paris] Before Theme (seven) :
    [26-May-2023 08:44:07 Europe/Paris] Before Theme (stark) :
    [26-May-2023 08:44:07 Europe/Paris] After Theme (adaptivetheme) :1
    [26-May-2023 08:44:07 Europe/Paris] After Theme (adaptivetheme_admin) :1
    [26-May-2023 08:44:07 Europe/Paris] After Theme (adaptivetheme_subtheme) :0
    [26-May-2023 08:44:07 Europe/Paris] After Theme (bartik) :1
    [26-May-2023 08:44:07 Europe/Paris] After Theme (f4r) :1
    [26-May-2023 08:44:07 Europe/Paris] After Theme (garland) :0
    [26-May-2023 08:44:07 Europe/Paris] After Theme (seven) :1
    [26-May-2023 08:44:07 Europe/Paris] After Theme (stark) :0

    And this in PHP 8.1:

    [26-May-2023 08:46:34 Europe/Paris] Before Theme (adaptivetheme) :
    [26-May-2023 08:46:34 Europe/Paris] Before Theme (adaptivetheme_admin) :
    [26-May-2023 08:46:34 Europe/Paris] Before Theme (adaptivetheme_subtheme) :
    [26-May-2023 08:46:34 Europe/Paris] Before Theme (bartik) :
    [26-May-2023 08:46:34 Europe/Paris] Before Theme (f4r) :
    [26-May-2023 08:46:34 Europe/Paris] Before Theme (garland) :
    [26-May-2023 08:46:34 Europe/Paris] Before Theme (seven) :
    [26-May-2023 08:46:34 Europe/Paris] Before Theme (stark) :
    [26-May-2023 08:46:34 Europe/Paris] After Theme (adaptivetheme) :0
    [26-May-2023 08:46:34 Europe/Paris] After Theme (adaptivetheme_admin) :0
    [26-May-2023 08:46:34 Europe/Paris] After Theme (adaptivetheme_subtheme) :0
    [26-May-2023 08:46:34 Europe/Paris] After Theme (bartik) :0
    [26-May-2023 08:46:34 Europe/Paris] After Theme (f4r) :0
    [26-May-2023 08:46:34 Europe/Paris] After Theme (garland) :0
    [26-May-2023 08:46:34 Europe/Paris] After Theme (seven) :0
    [26-May-2023 08:46:34 Europe/Paris] After Theme (stark) :0

  • 🇪🇸Spain JOINSO Sabadell

    Now this is solved fixing the database status in themes, but still getting "access denied" in some themes....

  • 🇪🇸Spain JOINSO Sabadell

    Just "disable/enable" clean urls or "clear cache" to fix.

    So, in brief:

    This is not safe in PHP 8.1:

    $theme_group_titles = array(
    'enabled' => format_plural(count($theme_groups['enabled']), 'Enabled theme', 'Enabled themes'),
    );

    If all the themes are disabled (status=0 in database).

  • Status changed to Postponed: needs info 8 months ago
  • 🇸🇰Slovakia poker10

    Thanks for reporting this. I do not think you can disable all themes via Drupal 7 UI. Therefore we need more information how you ended up with all themes disabled. If this was an error like deleting all themes, or similar, then it is not a bug in Drupal core and it is unlikely we are going to commit this patch. Thanks!

  • 🇬🇧United Kingdom andrew.farquharson

    andrew.farquharson made their first commit to this issue’s fork.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update 7 months ago
    2,163 pass
  • 🇬🇧United Kingdom andrew.farquharson

    HI @poker10, I tested on a fresh cloned installation. I unticked the logo setting for the default bartik theme https://www.drupal.org/files/issues/2023-11-17/clean-install-bartik-theme.png . That triggered an error in recent log messages. Recent log messages Two errors were triggered in the system.admin.inc file. First of 2 errors The error was due to null argument for the array in in_array() functions Error message details

    This is a known PHP 8.1 issue. Fix for in_array function issue

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 7.4 & MySQL 5.7
    last update 7 months ago
    2,163 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.2 & pgsql-13.5
    last update 7 months ago
    2,124 pass
  • last update 7 months ago
    2,163 pass
  • 🇸🇰Slovakia poker10

    Thanks @andrew.farquharson, but I think that what you reported is a slightly different issue than the one mentioned in the IS. The issue from @JOINSO is with $theme_groups['enabled'] being empty.

    Anyway, I also have a clean Drupal 7.98 install and the default frontent theme set to Bartik. Running on PHP 8.1 and unchecked the Logo, there are no messages in my watchdog. Are there any other steps/configuration changes needed?

    The source of the mentioned typeError in your watchdog seem to be this: $features = $themes[$key]->info['features']; (the features are empty). But I do not think that the features can be empty for Bartik theme, because there are no features in the .info file, so Drupal will initialize the default array:

    $themes[$key]->info = drupal_parse_info_file($theme->uri) + $defaults;
    

    And the $defaults['features'] are:

    function _system_default_theme_features() {
      return array(
        'logo',
        'favicon',
        'name',
        'slogan',
        'node_user_picture',
        'comment_user_picture',
        'comment_user_verification',
        'main_menu',
        'secondary_menu',
      );
    }
    
  • 🇬🇧United Kingdom andrew.farquharson

    @poker10 Hi, yes the other step was to save the configuration of bartik after deselecting the logo setting. I am not sure if you assumed that step or did exactly as i stated? If you could try it and perhaps deselect a few more of the settings, saving the configuration and re-checking the recent errors, please. I will try to reproduce the error once again if you cannot. Thanks.

  • 🇬🇧United Kingdom andrew.farquharson

    @poker10 I just did a drush site-install using standard profile. I have switched to the 7.x branch. I deleted all recent log messages. Then deselected the logo setting for bartik and saved the configuration. Then went to reports> recent log messages. The php typeerror was the most recent entry and also the only error.

  • 🇸🇰Slovakia poker10

    Thanks @andrew.farquharson. This looks like a bug in the color module, not in the function which your changes in MR are trying to fix. Color module displays a preview which contains the logo. This JS (themes/bartik/color/preview.js) is modifying the preview:

         // Change the logo to be the real one.
          if (!this.logoChanged) {
            $('#preview #preview-logo img').attr('src', Drupal.settings.color.logo);
            this.logoChanged = true;
          }
          // Remove the logo if the setting is toggled off. 
          if (Drupal.settings.color.logo == null) {
            $('div').remove('#preview-logo');
          }
    

    The problem with this code seems like that when Drupal.settings.color.logo is NULL (e.g. the checkbox is unchecked), it will generate this URL for the logo: admin/appearance/settings/null. This URL will generate all warnings and errors. We should fix this in the JS, not in the modules/system/system.admin.inc because that will only hide the real problem.

    So I recommend these next steps:

    1. Revert the changes from the MR and keep only the initial changes made by @JOINSO, as this issue is unrelated
    2. Create a new issue with this color module bug with all information needed (feel free to link it here)
    3. We can take a look in the new issue

    Thanks!

  • 🇬🇧United Kingdom andrew.farquharson

    @poker10

    (e.g. the checkbox is unchecked)

    There are, in fact, three checkboxes which each is deselected while the other 2 are selected will trigger the error.

    The errors only occurs when using PHP 8.1 with Drupal 7.x. The fix I have applied is one that is used in PHP applications that rely on PHP 8.1, across the board. e.g. Laravel. Every previous version of PHP does not expose any faults in the code, color module, bartik or anywhere else. So I would say this is not a color module issue so much as a PHP 8.1 issue. I have applied a PHP 8.1 fix. It is extremely simple and effective, though I have not tested all the possible deselect permutations yet with the fix, only without the fix: they all trigger the same error.

  • 🇸🇰Slovakia poker10

    The errors only occurs when using PHP 8.1 with Drupal 7.x.

    I explained that in the other issue already. This was a problem also earlier, but PHP 8+ introduced TypeErrors so some warnings are now errors. Before it was working, but the warnings were there as well.

    I would say this is not a color module issue so much as a PHP 8.1 issue.

    This is not true, I have debugged and explained that in #16.

    So please, let's focus on my recommendations from #16. Discussing this here is out of scope of the original problem, see: https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquett... , so you need to create a new issue.

  • 🇬🇧United Kingdom andrew.farquharson

    @poker10 i regard this as a waste of time now. Good luck.

Production build 0.69.0 2024