TypeError: Unsupported operand types: null + array

Created on 25 September 2023, over 1 year ago
Updated 28 September 2023, over 1 year ago

We have office hours on a taxonomy term. The hours themselves work fine, but as soon as we add an exception and try to save the term we get this error

TypeError: Unsupported operand types: null + array in Drupal\office_hours\Element\OfficeHoursBaseSlot::valueCallback()

Looking where the error is pointing, it is saying that `$input` is NULL. I added another type check and that seemed to solve the problem.

Here it is in 1.11:

  public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
    if ($input !== FALSE) {
      // Massage, normalize value after pressing Form button.
      // $element is also updated via reference.
      $input += ['day_delta' => $element['#day_delta']];
      $input = OfficeHoursItem::formatValue($input);

      return $input;
    }

    return NULL;
  }

With the code updated it now checks if it is also not NULL.

  public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
    if ($input !== FALSE && $input !== NULL) {
      // Massage, normalize value after pressing Form button.
      // $element is also updated via reference.
      $input += ['day_delta' => $element['#day_delta']];
      $input = OfficeHoursItem::formatValue($input);

      return $input;
    }

    return NULL;
  }

I am not noticing any problems with this, however, I want to see if anyone can see this causing a problem. I will post a patch shortly.

πŸ› Bug report
Status

Fixed

Version

1.11

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States rondog469

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

Comments & Activities

Production build 0.71.5 2024