Skip to content

Detect legacy HTML in content_builder value and offer one-click migration to a slice - #20

Closed
skerbis with Copilot wants to merge 3 commits into
mainfrom
copilot/yform-value-html-detection
Closed

Detect legacy HTML in content_builder value and offer one-click migration to a slice#20
skerbis with Copilot wants to merge 3 commits into
mainfrom
copilot/yform-value-html-detection

Conversation

Copilot AI commented May 28, 2026

Copy link
Copy Markdown

When a content_builder YForm field already contains classic HTML (e.g. migrated from a legacy textarea/WYSIWYG field), the value was silently dropped because parseValue() returned [] for any non-JSON input. The field should instead recognize HTML, expose it in a CKE5/TinyMCE editor using the admin-configured profile, and let the editor migrate it into a Content Builder slice.

Changes

  • Settings (pages/settings.php, lang files) – new addon configs legacy_editor (none | cke5 | tinymce) and legacy_profile. Per-field overrides exposed via getDefinitions().
  • rex_yform_value_content_builder::getTemplateVars() – when the raw value is non-empty and not a valid JSON array, the original string is forwarded to the template as legacy_html along with the resolved legacy_editor / legacy_profile.
  • ytemplates/bootstrap/value.content_builder.tpl.php – if legacy_html is present and a legacy editor is configured, renders a alert-warning bar with a "Convert to Content Builder" button plus a <textarea> carrying the cke5-editor / tiny-editor class and data-profile=… attribute. While legacy mode is active, the slices container, the add-element dropdown and the hidden JSON input are suppressed; the textarea uses the YForm field name directly so plain saves preserve the value.
  • assets/content-builder.js
    • initLegacyEditors() boots the appropriate editor via the existing cke5_init / tiny_init helpers.
    • migrateLegacyHtml() reads the current editor content (tinymce.get(id), then ckeditors[id] for CKE5, fallback to textarea value), destroys the editor instance, removes the legacy block, calls addSlice(..., 'starter_text', …) and pre-fills data-slice-data with { text: html }, then re-emits the hidden JSON input.
  • assets/content-builder.css – minor flex layout for the notice bar.

Detection logic

$rawValue = (string) $this->getValue();
$legacyHtml = '';
if ($rawValue !== '' && empty($value)) {           // parseValue() returned []
    $decoded = json_decode($rawValue, true);
    if (!is_array($decoded)) {                     // not Content Builder JSON
        $legacyHtml = $rawValue;
    }
}

Notes for review

  • Migration target is hard-coded to starter_text / field text. If a project replaces that element it should still work as long as the field key remains text; otherwise we may want to make the target configurable.
  • The legacy editor profile is passed through as data-profile (matching how Cke5Field / TinyMceField render their textareas), so existing profile handling on the addon side applies unchanged.
  • No DB migration is required – detection is read-only against the existing column.

Copilot AI linked an issue May 28, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add functionality to detect HTML content in yform value Detect legacy HTML in content_builder value and offer one-click migration to a slice May 28, 2026
Copilot AI requested a review from skerbis May 28, 2026 17:31
@skerbis

skerbis commented May 30, 2026

Copy link
Copy Markdown
Member

@copilot ist es fertig?

Copilot AI commented May 30, 2026

Copy link
Copy Markdown
Author

@copilot ist es fertig?

Ja, die Änderungen aus der PR-Beschreibung sind committet (siehe be3f058 für die Hauptimplementierung und 916b3d9 für das Cleanup rund um die CKE5-Instanz/Editor-ID). Aus meiner Sicht ist die Arbeit damit abgeschlossen und bereit für deinen finalen Review/Test. Falls dir beim Ausprobieren noch etwas auffällt (z. B. anderes Migrationsziel als starter_text/text), gib Bescheid – dann passe ich es an.

@skerbis skerbis closed this May 30, 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.

Yform Value

2 participants