From 00d0500c33f3c2626ba391c2a1d33852af313933 Mon Sep 17 00:00:00 2001 From: Ivan Bochkarev Date: Tue, 11 Aug 2026 07:35:32 +0600 Subject: [PATCH 1/4] Fix undefined array key "desc" in element property lexicon translation Guard property description lookup in modElement::get() and modPropertySet::get() when the desc key is missing, preventing PHP 8 warnings in the manager log. --- .../Tests/Model/Element/modElementTest.php | 55 +++++++++++++++++++ core/src/Revolution/modElement.php | 3 +- core/src/Revolution/modPropertySet.php | 3 +- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/_build/test/Tests/Model/Element/modElementTest.php b/_build/test/Tests/Model/Element/modElementTest.php index 128faa41748..973bd16e19b 100644 --- a/_build/test/Tests/Model/Element/modElementTest.php +++ b/_build/test/Tests/Model/Element/modElementTest.php @@ -151,6 +151,61 @@ public function providerProcess() { ]; } + /** + * Property definitions without a desc key must not trigger PHP warnings on get('properties'). + * + * @dataProvider providerGetPropertiesWithoutDescKey + * @param array $propertyDefinition + * @param string $expectedDescTrans + */ + public function testGetPropertiesWithoutDescKey(array $propertyDefinition, string $expectedDescTrans) + { + /** @var modElement $element */ + $element = $this->modx->newObject(modElement::class); + $element->set('properties', [$propertyDefinition]); + + $warnings = []; + set_error_handler(static function ($severity, $message) use (&$warnings) { + if ($severity === E_WARNING) { + $warnings[] = $message; + } + return true; + }, E_WARNING); + + try { + $properties = $element->get('properties'); + } finally { + restore_error_handler(); + } + + $this->assertSame([], $warnings, 'Expected no PHP warnings when desc is missing'); + $this->assertArrayHasKey('desc_trans', $properties[0]); + $this->assertSame($expectedDescTrans, $properties[0]['desc_trans']); + } + + public function providerGetPropertiesWithoutDescKey() + { + return [ + 'missing desc' => [ + [ + 'name' => 'foo', + 'type' => 'textfield', + 'value' => 'bar', + ], + '', + ], + 'description fallback' => [ + [ + 'name' => 'foo', + 'type' => 'textfield', + 'value' => 'bar', + 'description' => 'foo_desc', + ], + 'foo_desc', + ], + ]; + } + /** * Test the modElement->getTag() method with xPDOObjects as values. * E.g the nodes when the event `OnResourceSort` is fired diff --git a/core/src/Revolution/modElement.php b/core/src/Revolution/modElement.php index 3df81a99042..94a4c2c0832 100644 --- a/core/src/Revolution/modElement.php +++ b/core/src/Revolution/modElement.php @@ -162,7 +162,8 @@ public function get($k, $format = null, $formatTemplate = null) } $this->xpdo->lexicon->load($property['lexicon']); } - $property['desc_trans'] = $this->xpdo->lexicon($property['desc']); + $desc = $property['desc'] ?? $property['description'] ?? ''; + $property['desc_trans'] = $desc !== '' ? $this->xpdo->lexicon($desc) : ''; $property['area'] = !empty($property['area']) ? $property['area'] : ''; $property['area_trans'] = !empty($property['area']) ? $this->xpdo->lexicon($property['area']) : ''; diff --git a/core/src/Revolution/modPropertySet.php b/core/src/Revolution/modPropertySet.php index 3af5fb40a8b..06e10bd41bf 100644 --- a/core/src/Revolution/modPropertySet.php +++ b/core/src/Revolution/modPropertySet.php @@ -75,7 +75,8 @@ public function get($k, $format = null, $formatTemplate = null) } $this->xpdo->lexicon->load($property['lexicon']); } - $property['desc_trans'] = $this->xpdo->lexicon($property['desc']); + $desc = $property['desc'] ?? $property['description'] ?? ''; + $property['desc_trans'] = $desc !== '' ? $this->xpdo->lexicon($desc) : ''; $property['area'] = !empty($property['area']) ? $property['area'] : ''; if (!empty($property['options'])) { From a796f2347b3f7230064d6ff715094a16514163f3 Mon Sep 17 00:00:00 2001 From: Ivan Bochkarev Date: Wed, 12 Aug 2026 20:03:02 +0600 Subject: [PATCH 2/4] Remove test covering missing desc key in element properties. --- .../Tests/Model/Element/modElementTest.php | 55 ------------------- 1 file changed, 55 deletions(-) diff --git a/_build/test/Tests/Model/Element/modElementTest.php b/_build/test/Tests/Model/Element/modElementTest.php index 973bd16e19b..128faa41748 100644 --- a/_build/test/Tests/Model/Element/modElementTest.php +++ b/_build/test/Tests/Model/Element/modElementTest.php @@ -151,61 +151,6 @@ public function providerProcess() { ]; } - /** - * Property definitions without a desc key must not trigger PHP warnings on get('properties'). - * - * @dataProvider providerGetPropertiesWithoutDescKey - * @param array $propertyDefinition - * @param string $expectedDescTrans - */ - public function testGetPropertiesWithoutDescKey(array $propertyDefinition, string $expectedDescTrans) - { - /** @var modElement $element */ - $element = $this->modx->newObject(modElement::class); - $element->set('properties', [$propertyDefinition]); - - $warnings = []; - set_error_handler(static function ($severity, $message) use (&$warnings) { - if ($severity === E_WARNING) { - $warnings[] = $message; - } - return true; - }, E_WARNING); - - try { - $properties = $element->get('properties'); - } finally { - restore_error_handler(); - } - - $this->assertSame([], $warnings, 'Expected no PHP warnings when desc is missing'); - $this->assertArrayHasKey('desc_trans', $properties[0]); - $this->assertSame($expectedDescTrans, $properties[0]['desc_trans']); - } - - public function providerGetPropertiesWithoutDescKey() - { - return [ - 'missing desc' => [ - [ - 'name' => 'foo', - 'type' => 'textfield', - 'value' => 'bar', - ], - '', - ], - 'description fallback' => [ - [ - 'name' => 'foo', - 'type' => 'textfield', - 'value' => 'bar', - 'description' => 'foo_desc', - ], - 'foo_desc', - ], - ]; - } - /** * Test the modElement->getTag() method with xPDOObjects as values. * E.g the nodes when the event `OnResourceSort` is fired From 604fc5d9a37919d6aada09ce6171f46c9c07b5a9 Mon Sep 17 00:00:00 2001 From: Bochkarev Ivan Date: Thu, 13 Aug 2026 21:25:45 +0600 Subject: [PATCH 3/4] Update core/src/Revolution/modElement.php Co-authored-by: Jim Graham --- core/src/Revolution/modElement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/Revolution/modElement.php b/core/src/Revolution/modElement.php index 94a4c2c0832..9b61e9ea3dd 100644 --- a/core/src/Revolution/modElement.php +++ b/core/src/Revolution/modElement.php @@ -162,7 +162,7 @@ public function get($k, $format = null, $formatTemplate = null) } $this->xpdo->lexicon->load($property['lexicon']); } - $desc = $property['desc'] ?? $property['description'] ?? ''; + $desc = $property['desc'] ?? ''; $property['desc_trans'] = $desc !== '' ? $this->xpdo->lexicon($desc) : ''; $property['area'] = !empty($property['area']) ? $property['area'] : ''; $property['area_trans'] = !empty($property['area']) ? $this->xpdo->lexicon($property['area']) : ''; From 3e72b03682a78a784dfb3883d5e330d2b9c15580 Mon Sep 17 00:00:00 2001 From: Bochkarev Ivan Date: Thu, 13 Aug 2026 21:25:55 +0600 Subject: [PATCH 4/4] Update core/src/Revolution/modPropertySet.php Co-authored-by: Jim Graham --- core/src/Revolution/modPropertySet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/Revolution/modPropertySet.php b/core/src/Revolution/modPropertySet.php index 06e10bd41bf..3fd1a756f86 100644 --- a/core/src/Revolution/modPropertySet.php +++ b/core/src/Revolution/modPropertySet.php @@ -75,7 +75,7 @@ public function get($k, $format = null, $formatTemplate = null) } $this->xpdo->lexicon->load($property['lexicon']); } - $desc = $property['desc'] ?? $property['description'] ?? ''; + $desc = $property['desc'] ?? ''; $property['desc_trans'] = $desc !== '' ? $this->xpdo->lexicon($desc) : ''; $property['area'] = !empty($property['area']) ? $property['area'] : '';