### Problem/Motivation
When requesting a translation via the TMGMT content or config translation forms, if a `TMGMTException` is thrown (e.g., when source content is empty), the error handler crashes with a TypeError instead of displaying the intended error message.
**Error:**
TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /var/www/docroot/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 238
### Steps to reproduce
1. Navigate to any content translation page (e.g., `/node/123/translations`)
2. Select a target language (e.g., Spanish)
3. Click "Request Translation"
4. If the source content triggers a `TMGMTException` (e.g., empty content), the site crashes with a TypeError instead of showing the error message
### Root cause
In both `ContentTranslateForm.php` (line 143) and `ConfigTranslateForm.php` (line 212), the code attempts to access a non-existent `->language` property on `Drupal\Core\Language\Language` objects:
$target_lang_name = $languages[$langcode]->language;
The Language class has a protected $name property that is only accessible via the public ->getName() method. Accessing ->language returns null, which then causes Html::escape() to throw a TypeError when the translation function attempts to format the error message placeholder.
Proposed resolution
Replace ->language with ->getName() in both files:
ContentTranslateForm.php (line 143):
// Before:
$target_lang_name = $languages[$langcode]->language;
// After:
$target_lang_name = $languages[$langcode]->getName();
ConfigTranslateForm.php (line 212):
// Before:
$target_lang_name = $languages[$langcode]->language;
// After:
$target_lang_name = $languages[$langcode]->getName();
Environment
- TMGMT version: 1.17.0
- Drupal version: 11.3.1
- PHP version: 8.4.5
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | tmgmt-language-property-typeerror-3565724-1.patch | 1.58 KB | bkildow |
Comments
Comment #2
bkildow commented