Handle malformed module info in the translation status form

Created on 16 February 2024, 9 months ago
Updated 27 March 2024, 8 months ago

Problem/Motivation

In some circumstances in page /admin/reports/translations 'Available translation updates' sets of 3 warnings happens,

Warning: Undefined array key "datatables"
in Drupal\locale\Form\TranslationStatusForm->prepareUpdateData() (line 203 of core/modules/locale/src/Form/TranslationStatusForm.php).
Warning: Attempt to read property "info" on null
in Drupal\locale\Form\TranslationStatusForm->prepareUpdateData() (line 203 of core/modules/locale/src/Form/TranslationStatusForm.php).
Warning: Trying to access array offset on value of type null
in Drupal\locale\Form\TranslationStatusForm->prepareUpdateData() (line 203 of core/modules/locale/src/Form/TranslationStatusForm.php).

With the additional message,

#0 */web/core/includes/bootstrap.inc(164): _drupal_error_handler_real()
#1 */web/core/modules/locale/src/Form/TranslationStatusForm.php(203): _drupal_error_handler()
#2 */web/core/modules/locale/src/Form/TranslationStatusForm.php(78): Drupal\locale\Form\TranslationStatusForm->prepareUpdateData()
#3 [internal function]: Drupal\locale\Form\TranslationStatusForm->buildForm()
#4 */web/core/lib/Drupal/Core/Form/FormBuilder.php(536): call_user_func_array()
#5 */web/core/lib/Drupal/Core/Form/FormBuilder.php(283): Drupal\Core\Form\FormBuilder->retrieveForm()
#6 */web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()

Where "datatables" is a module and could be different. The line 203 in core/modules/locale/src/Form/TranslationStatusForm.php is,

'name' => $project_info->name == 'drupal' ? $this->t('Drupal core') : $project_data[$project_info->name]->info['name'],

$project_info->name is the module name. $project_data[$project_info->name]->info['name'] is the value of the key project in the file <module name>.info.yml. Such a problem happens for a module when no key project exists in its info.yml file.

Steps to reproduce

With Drupal 10.2 in page /admin/reports/translations.
If no problems exist alter the info.yml of a module removing the line project.

Proposed resolution

These are errors/warnings and should be corrected. Actually to solve the problem the file info.yml should have the key project with a value. This key is one of the ones automatically add to the file info.yml by Drupal.org packaging script when a new release is created, with keys version and datestamp.
- Either the rule stands that a module should have file info.yml with the key project,
- Or the logic of this code might be changed.
However what is actually a list of modules producing errors could be changed in a list of modules with an abnormal info.yml file. A potentially interesting information. Here stands a means to get it.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
LocaleΒ  β†’

Last updated 4 days ago

Created by

πŸ‡«πŸ‡·France Chris64 France

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

Comments & Activities

  • Issue created by @Chris64
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    I tested this on Drupal 11.x today with umami install and using the pirate module. I was able to recreat the problem, therefor changing version.

    I tracked this to \Drupal\Core\Utility\ProjectInfo::processInfoList().

          // If the .info.yml doesn't define the 'project', try to figure it out.
          if (!isset($file->info['project'])) {
            $file->info['project'] = $this->getProjectName($file);
          }
  • πŸ‡«πŸ‡·France Chris64 France

    Yes, in core/lib/Drupal/Core/Utility/ProjectInfo.php. And just following,

          // If we still don't know the 'project', give up.
          if (empty($file->info['project'])) {
            continue;
          }

    living the loop foreach ($list as $file) and missing the setting,

          if (!isset($projects[$project_name])) {
            // Only process this if we haven't done this project, since a single
            // project can have multiple modules or themes.
            $projects[$project_name] = [
              'name' => $project_name,
              // Only save attributes from the .info.yml file we care about so we do
              // not bloat our RAM usage needlessly.
              'info' => $this->filterProjectInfo($file->info, $additional_elements),
              'datestamp' => $file->info['datestamp'],
              'includes' => [$file->getName() => $file->info['name']],
              'project_type' => $project_display_type,
              'project_status' => $status,
            ];
          }
Production build 0.71.5 2024