LogicException: The database connection is not serializable.

Created on 15 April 2024, 7 months ago

Problem/Motivation

Using a custom file_managed type field on theme settings breaks.
Related META core issue: 🐛 LogicException: The database connection is not serializable (for string translations in Ajax callback) [META] Active

Steps to reproduce

Install the gs_paragraphs module
Create a hook to add a file_managed type field on theme settings
Example:

/**
 * Implements hook_form_system_theme_settings_alter().
 */
function test_form_system_theme_settings_alter(&$form, FormStateInterface $form_state) {
  $form['custom_logo'] = [
    '#type' => 'managed_file',
    '#title' => t('Contact image'),
    '#description' => t('Upload the contact image.'),
    '#default_value' => theme_get_setting('contact_image'),
    '#progress_indicator' => 'bar',
    '#progress_message'   => t('Please wait...'),
    '#upload_location' => 'public://test',
  ];
  $form['#submit'][] = 'test_theme_settings_form_system_theme_settings_submit';
}
/**
 * Test theme form settings submission handler.
 */
function test_theme_settings_form_system_theme_settings_submit(&$form, FormStateInterface $form_state) {
  if ($file_id = $form_state->getValue(['custom_logo', '0'])) {
    $file = File::load($file_id);
    $file->setPermanent();
    $file->save();
  }
}

Proposed resolution

Understand the problem and provide a patch for it.

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇧🇷Brazil hmendes

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024