Skip to content

Respect useCustomLinkForClassicWidgets for medialist and linklist#432

Closed
thorol wants to merge 4 commits into
FriendsOfREDAXO:mainfrom
thorol:main
Closed

Respect useCustomLinkForClassicWidgets for medialist and linklist#432
thorol wants to merge 4 commits into
FriendsOfREDAXO:mainfrom
thorol:main

Conversation

@thorol

@thorol thorol commented May 29, 2026

Copy link
Copy Markdown
Contributor

Closes #431

Summary by CodeRabbit

  • Documentation

    • Dokumentation der Widget-Feldbehandlung aktualisiert, um die Unterstützung für Medialist- und Linklistfelder zu verdeutlichen.
  • Bug Fixes

    • Widget-Rendering für Media- und Linklistfelder optimiert, um korrekt auf Konfigurationseinstellungen zu reagieren.

Review Change Stack

@thorol thorol requested a review from skerbis May 29, 2026 21:49
@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Moin,

Walkthrough

Die Änderung stellt Rückwärtskompatibilität her: addLinklistField() und addMedialistField() respektieren jetzt das useCustomLinkForClassicWidgets-Flag wie addLinkField(). Dokumentation wurde erweitert, Imports ergänzt, Tab-Rendering vereinfacht, und Widget-Auswahl wird bedingt am Schalter entlang gesteuert.

Changes

Widget-Kompatibilität und Dokumentation

Layer / File(s) Summary
Dokumentation und Imports
lib/MForm.php, lib/MForm/Parser/MFormParser.php
Docblock von $useCustomLinkForClassicWidgets erweitert, um addMedialistField() und addLinklistField() explizit zu nennen; fehlende Imports für rex_var_linklist, rex_var_medialist und rex_var_media hinzugefügt.
Tab-Rendering vereinfacht
lib/MForm/Parser/MFormParser.php
Wrapper-Öffnung für Tab-Elemente reduziert auf Kernlogik: Navigation-ID und optionale aktive Markierung; Layout/Style-CSS-Ableitungen und Attribut-Bereinigung entfernt.
Bedingte Widget-Auswahl
lib/MForm/Parser/MFormParser.php
generateMediaElement() für medialist und generateLinkElement() für linklist wählen Widget nun über MForm::isUsingCustomLinkForClassicWidgets(): klassische Rex-Widgets oder MForm-Varianten; nachfolgende DOM-Verarbeitung unverändert.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Der Pull-Request-Titel beschreibt präzise die Hauptänderung: Respektierung des useCustomLinkForClassicWidgets-Schalters für medialist und linklist.
Linked Issues check ✅ Passed Der PR adressiert alle Anforderungen aus Issue #431: linklist respektiert nun useCustomLinkForClassicWidgets() [#431], medialist wurde gleichgestellt [#431], und die Dokumentation wurde aktualisiert [#431].
Out of Scope Changes check ✅ Passed Alle Änderungen sind direkt auf die Anforderungen aus Issue #431 bezogen: Refactoring von linklist, medialist-Support und Dokumentationsaktualisierung.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
lib/MForm/Parser/MFormParser.php (1)

1128-1152: ⚡ Quick win

Moin, Code-Duplizierung in den Linklist-Widget-Branches.

Die DOM-Verarbeitung (Zeilen 1131-1139 und 1143-1151) ist in beiden Zweigen nahezu identisch. Nur der Aufruf von getWidget() unterscheidet sich. Die DOM-Verarbeitung sollte nach der bedingten Widget-Auswahl einmalig erfolgen.

♻️ Vorgeschlagene Refaktorierung
                 $value = is_array($item->getValue()) ? '' : (string) ($item->getValue() ?? '');
 
                 if (MForm::isUsingCustomLinkForClassicWidgets()) {
                     $html = rex_var_custom_linklist::getWidget($id, $inputValue . '[' . $this->varIdStr($item) . ']', $value, $parameter);
-
-                    $dom = new DOMDocument('1.0', 'utf-8');
-                    @$dom->loadHTML('<?xml encoding="utf-8" ?>' . $html);
-                    $selects = $dom->getElementsByTagName('select');
-                    $inputs = $dom->getElementsByTagName('input');
-
-                    $this->processNodeFormElements($selects, $item, 'REX_LINKLIST_SELECT_' . $id);
-                    $this->processNodeFormElements($inputs, $item, 'REX_LINKLIST_' . $id);
-
-                    $this->prepareLinkInput($dom, $inputs, $item, $attributes);
                 } else {
                     $html = rex_var_linklist::getWidget($id, $inputValue . '[' . $this->varIdStr($item) . ']', $value, $parameter);
+                }
 
-                    $dom = new DOMDocument('1.0', 'utf-8');
-                    @$dom->loadHTML('<?xml encoding="utf-8" ?>' . $html);
-                    $selects = $dom->getElementsByTagName('select');
-                    $inputs = $dom->getElementsByTagName('input');
-
-                    $this->processNodeFormElements($selects, $item, 'REX_LINKLIST_SELECT_' . $id);
-                    $this->processNodeFormElements($inputs, $item, 'REX_LINKLIST_' . $id);
-
-                    $this->prepareLinkInput($dom, $inputs, $item, $attributes);
-                }
+                $dom = new DOMDocument('1.0', 'utf-8');
+                @$dom->loadHTML('<?xml encoding="utf-8" ?>' . $html);
+                $selects = $dom->getElementsByTagName('select');
+                $inputs = $dom->getElementsByTagName('input');
+
+                $this->processNodeFormElements($selects, $item, 'REX_LINKLIST_SELECT_' . $id);
+                $this->processNodeFormElements($inputs, $item, 'REX_LINKLIST_' . $id);
+
+                $this->prepareLinkInput($dom, $inputs, $item, $attributes);
                 break;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/MForm/Parser/MFormParser.php` around lines 1128 - 1152, Extract the
differing widget creation into a single $html assignment by first using the
conditional to call either rex_var_custom_linklist::getWidget(...) or
rex_var_linklist::getWidget(...), then perform the DOM processing once: create
DOMDocument, loadHTML, getElementsByTagName for 'select' and 'input', call
$this->processNodeFormElements($selects, $item, 'REX_LINKLIST_SELECT_'.$id) and
$this->processNodeFormElements($inputs, $item, 'REX_LINKLIST_'.$id), and finally
$this->prepareLinkInput($dom, $inputs, $item, $attributes); keep
MForm::isUsingCustomLinkForClassicWidgets(), $id,
$inputValue.'['.$this->varIdStr($item).']', $value and $parameter exactly as
used to build the widget.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/MForm/Parser/MFormParser.php`:
- Line 330: Die Klasse wird ohne Trennzeichen angefügt; ändere den Aufruf so,
dass vor 'active' ein Leerzeichen eingefügt wird (z.B. ersetze
$item->setClass($item->getClass() . 'active') durch
$item->setClass(trim($item->getClass()) . ' active') oder baue bedingt ein
führendes Leerzeichen ein), referenziere dabei die Aufrufe von $item->getClass()
und $item->setClass() in MFormParser.

---

Nitpick comments:
In `@lib/MForm/Parser/MFormParser.php`:
- Around line 1128-1152: Extract the differing widget creation into a single
$html assignment by first using the conditional to call either
rex_var_custom_linklist::getWidget(...) or rex_var_linklist::getWidget(...),
then perform the DOM processing once: create DOMDocument, loadHTML,
getElementsByTagName for 'select' and 'input', call
$this->processNodeFormElements($selects, $item, 'REX_LINKLIST_SELECT_'.$id) and
$this->processNodeFormElements($inputs, $item, 'REX_LINKLIST_'.$id), and finally
$this->prepareLinkInput($dom, $inputs, $item, $attributes); keep
MForm::isUsingCustomLinkForClassicWidgets(), $id,
$inputValue.'['.$this->varIdStr($item).']', $value and $parameter exactly as
used to build the widget.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4f9a1e4d-f4f5-4041-a2c2-532b4dd83df3

📥 Commits

Reviewing files that changed from the base of the PR and between d508c3d and 7be76a3.

📒 Files selected for processing (2)
  • lib/MForm.php
  • lib/MForm/Parser/MFormParser.php

$attributes['data-tab-group-nav-tab-id'] = $item->getGroup() . $item->getGroupCount() . '_' . $item->getGroupKey();
if (isset($attributes['data-group-open-tab']) && true === $attributes['data-group-open-tab']) {
$item->setClass(trim($item->getClass() . ' active'));
$item->setClass($item->getClass() . 'active');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Moin, fehlendes Leerzeichen vor der CSS-Klasse active.

Die Klasse wird ohne Trennzeichen angehängt, was zu ungültigen CSS-Klassennamen führt (z. B. existing-classactive statt existing-class active).

🐛 Vorgeschlagener Fix
-                $item->setClass($item->getClass() . 'active');
+                $item->setClass($item->getClass() . ' active');
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$item->setClass($item->getClass() . 'active');
$item->setClass($item->getClass() . ' active');
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/MForm/Parser/MFormParser.php` at line 330, Die Klasse wird ohne
Trennzeichen angefügt; ändere den Aufruf so, dass vor 'active' ein Leerzeichen
eingefügt wird (z.B. ersetze $item->setClass($item->getClass() . 'active') durch
$item->setClass(trim($item->getClass()) . ' active') oder baue bedingt ein
führendes Leerzeichen ein), referenziere dabei die Aufrufe von $item->getClass()
und $item->setClass() in MFormParser.

@skerbis skerbis closed this May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

addLinklistField() ist nicht rueckwaertskompatibel wie addLinkField()

2 participants