Problem/Motivation

This error message is displayed on all pages after installing the module

Deprecated function: unserialize(): Passing null to parameter #1 ($data) of type string is deprecated in Drupal\Core\Entity\Sql\SqlContentEntityStorage->loadFromSharedTables() (line 603 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Drupal 11.1.5
Translatable Menu Link URI 2.1.3

Steps to reproduce

Install the module with composer

Comments

attraktive created an issue. See original summary.

attraktive’s picture

Issue summary: View changes
StatusFileSize
new182.11 KB
attraktive’s picture

Title: Deprecated function: unserialize(): Passing null to parameter #1 ($data) of type string is deprecated in Drupal\Core\Entity\Sql\SqlContentEntityStorage->loadFromSharedTables() (line 603 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php). » Deprecated function: unserialize(): Passing null to parameter #1 ($data) of type string is deprecated in Drupal\Core\Entity\Sql\SqlContentEntityStorage->loadFromSharedTables()
sokru’s picture

Version: 2.1.3 » 2.x-dev

This is fixed on core on Drupal 11.x #3300404: Handle nullable serialized field columns, this is due to link_override is not marked as required (so it can be NULL). I'd suggest closing this issue. One can cherry-pick the fix from core issue commit https://git.drupalcode.org/project/drupal/-/commit/4a32768c1632070e1438a..., it shall apply cleanly for latest releases.

jsobiecki’s picture

@sokru - Thank you for checking it! I'll double check it and if there are no better option, I'll close this ticket.

jsobiecki’s picture

Status: Active » Fixed

@sokru - Thank you for checking it! I’ll double-check it, and if there are no better options, I’ll close this ticket.
The upstream fix seems like the best option.

The upstream ticket discussion reports about a workaround, but I didn’t investigate it thoroughly:
https://www.drupal.org/project/drupal/issues/3300404#comment-14974105

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

jsobiecki’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

mariacha1’s picture

Attaching a quick Drupal 10-compatible patch here if it's useful for others.

mariacha1’s picture

Oh, and I also needed this update hook to make sure all the `link_override__options` values where non-null:


/**
 * Backfill NULL link_override__options to prevent unserialize() deprecation.
 */
function my_module_update_10006() {
  $database = \Drupal::database();
  $tables = [
    'menu_link_content_data',
    'menu_link_content_field_revision',
  ];

  foreach ($tables as $table) {
    if (!$database->schema()->fieldExists($table, 'link_override__options')) {
      continue;
    }

    $database->update($table)
      ->fields(['link_override__options' => serialize([])])
      ->isNull('link_override__options')
      ->execute();
  }
}