_menu_router_save() breaks when a theme.info file does not contain a "name" value

Created on 21 March 2014, about 10 years ago
Updated 18 April 2024, about 2 months ago

Inside of system.module, in the system_menu() hook, we have the following foreach loop. This loop is used to add a settings page for each theme. Here are lines 645 to 654 from system.module:

  foreach (list_themes() as $theme) {
    $items['admin/appearance/settings/' . $theme->name] = array(
      'title' => $theme->info['name'],
      'page arguments' => array('system_theme_settings', $theme->name),
      'type' => MENU_LOCAL_TASK,
      'access callback' => '_system_themes_access',
      'access arguments' => array($theme),
      'file' => 'system.admin.inc',
    );
  }

The list_themes() function feeds this foreach loop. But, if any theme has an empty .info file, or if the "name" parameter is missing from the .info file, a problem occurs. When this happens, $theme->info['name'] will be NULL in the above loop. The effect of this is as follows:

When _menu_router_save() tries to save the settings page for this theme, the 'title' value will be NULL and a PDOException will be thrown. This is the error thrown from _menu_router_save():

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be nulll: INSERT INTO {menu_router} (path, load_functions, to_arg_functions, access_callback, access_arguments, page_callback, page_arguments, delivery_callback, fit, number_parts, context, tab_parent, tab_root, title, title_callback, title_arguments, theme_callback, theme_arguments, type, description, position, weight, include_file) VALUES ( [...] ) in _menu_router_save() (line 3837 of /includes/menu.inc).

In normal circumstances, there should never be a theme without a name in its .info file, but it happened to me accidentally and it was very hard to troubleshoot.

Themes without names should either be excluded from list_themes(), or the theme folder name should be used as the default theme name.

🐛 Bug report
Status

Needs review

Version

7.0 ⚰️

Component
System 

Last updated 2 days ago

No maintainer
Created by

🇨🇦Canada hellolindsay

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024