php 8.1:TypeError: strlen(): Argument #1 ($string) must be of type string, array given

Created on 3 August 2023, over 1 year ago
Updated 25 October 2023, about 1 year ago

Problem/Motivation

TypeError: strlen(): Argument #1 ($string) must be of type string, array given
in /var/www/html/core/lib/Drupal/Component/Utility/Unicode.php on line 477
#0 /var/www/html/core/lib/Drupal/Component/Utility/Unicode.php(477): strlen()
#1 /var/www/html/core/lib/Drupal/Component/Utility/Xss.php(65): Drupal\\Component\\Utility\\Unicode::validateUtf8()
#2 /var/www/html/modules/contrib/fullcalendar_view/src/FullcalendarViewPreprocess.php(170): Drupal\\Component\\Utility\\Xss::filter()
#3 /var/www/html/modules/contrib/fullcalendar_view/fullcalendar_view.theme.inc(32): Drupal\\fullcalendar_view\\FullcalendarViewPreprocess->process()
#4 [internal function]: template_preprocess_views_view_fullcalendar()

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: works as designed

Version

5.1

Component

Code

Created by

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

  • Issue created by @sana.shamsudin
  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    Please provide steps to reproduce the error and the raw data of the view and content.

  • The issue occurs when we install the module's latest version in Drupal php 8.1version.

  • πŸ‡ΈπŸ‡ͺSweden joos

    I can confirm this error and the fix (for me at least) was to open the view, edit format settings and assign a start and end date field.
    Save, flush cache and all is good.

  • Status changed to Active over 1 year ago
  • Status changed to RTBC over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    I can't reproduce this error on my sites.

    It could occur in a certain circumstances.

    Please provide more details how this happened, which would make way easier for others to do the trouble shooting and understand why it happens.

    The raw data of the view output will tell what really cause this issue.

  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί
  • πŸ‡¦πŸ‡ΉAustria anschinsan

    I tracked it down to:
    $left_buttons = Xss::filter($options['left_buttons']); and
    $right_buttons = Xss::filter($options['right_buttons']);

    lines 168 and line 170 in Drupal\fullcalendar_view\FullcalendarViewPreprocess

    strlen() does not accept an array, Xss::filter is using a method Unicode::validateUtf8, which is using strlen().

  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    $options['left_buttons'] and $options['right_buttons'] should be a string, right?

    Why an array return?

  • πŸ‡ΊπŸ‡ΈUnited States Dave Kopecek

    I believe the issue is with $options['right_buttons']. Using xdebug I see the value below at FullcalendarViewPreprocess.php line 170"

    $options['right_buttons'] =
    array(7)
    0:"dayGridMonth"
    1:"timeGridWeek"
    2:"timeGridDay"
    3:"listYear"
    agendaWeek:"agendaWeek"
    agendaDay:"agendaDay"
    listYear:"listYear"
    
  • πŸ‡ΊπŸ‡ΈUnited States Dave Kopecek

    I was able to `drush config:export` and manually update views.view.calendar.yml from:

              right_buttons:
                agendaWeek: agendaWeek
                agendaDay: agendaDay
                listYear: listYear
              default_view: month
    

    to

              left_buttons: 'prev,next today'
              right_buttons: 'dayGridMonth,timeGridWeek,timeGridDay,listYear'
              default_view: dayGridMonth
    

    after importing the config I manually edited and re-saved the settings in the view, cleared the cache and the error resolved.

  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    Once the view setting is saved, following line in the form submit function will convert the array into a string.

    $options['right_buttons'] = isset($options['right_buttons']) ? implode(',', array_filter(array_values($options['right_buttons']))) : 'dayGridMonth,timeGridWeek,timeGridDay,listYear';
    

    You can see the above source code at

    https://git.drupalcode.org/project/fullcalendar_view/-/blob/5.1.13/src/P...

    And also, the following buttons options are not provided by 5.x version.

    • agendaWeek
    • agendaDay

    The options available in 5.x version are:

        $fullcalendar_displays = [
          'dayGridMonth' => $this->t('Month'),
          'timeGridWeek' => $this->t('Week'),
          'timeGridDay' => $this->t('Day'),
          'listYear' => $this->t('List (Year)'),
          'listMonth' => $this->t('List (Month)'),
          'listWeek' => $this->t('List (Week)'),
          'listDay' => $this->t('List (Day)'),
        ];
    

    https://git.drupalcode.org/project/fullcalendar_view/-/blob/5.1.13/src/P...

    @David Kopecek, did you upgrade this module from 2.x? If so, as suggested in #6, what you need to do is just to re-save this view again. That is it.

    Every time you save the view setting, the option value will be converted into string as explained above.

    Other possibility is that you have some out-of-date configuration YML files remained in your configuration export folder. If that is the case, you also need to clean up/ update those YML files as well. Otherwise, once you re-import those out-of-date configuration back to your site, a misconfiguring issue like this one will occure again.

  • Status changed to Closed: works as designed about 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    I close it as it is a misconfiguring issue.

    As advised in the 'Upgrade path' session in the project page, if you upgrade this module from 2.x, you have to re-configure/re-save the view. And also you can't re-import the configuration exported for 2.x version. It won't work.

Production build 0.71.5 2024