adobe / aem-core-wcm-components

Standardized components to build websites with AEM.
https://docs.adobe.com/content/help/en/experience-manager-core-components/using/introduction.html
Apache License 2.0
733 stars 741 forks source link

[Teaser]: Mapping from get title from linked page not work correctly #2392

Open tmastalirsch opened 1 year ago

tmastalirsch commented 1 year ago

Bug Report

Current Behavior I found a bug in the implementation of the Teaser Model. Via the dialog I want to specify the title of the linked page. There is a difference between what is in the dialog and what is rendered into the component. In the dialog the jcr:title is specified, in the component the pageTitle.

In the getTitle method the getPageTitle method is also used first. (v1/TeaserImpl, v2/TeaserImpl)

Expected behavior/code The title from the linked page should match the dialog when rendering the component

Environment

Additional context / Screenshots dialog

crx

v1:Teaser

v2:Teaser

HitmanInWis commented 4 months ago

The issue appears to be in the teaser.js editor clientlib - apps/core/wcm/components/teaser/v2/teaser/clientlibs/editor/js/teaser.js

It can be fixed by adding a function:

function getPageTitle(pageData) {
        var title = pageData["pageTitle"] || "";
        if (title === "") {
            title = pageData["jcr:title"];
        }
        return title;
    }

Then you need to update two separate cases where jcr:title was being used directly by the dialog for default titles.

This fixes the default teaser title when inherited from the linked page:

// Line 114
titleTuple.seedTextValue(data["jcr:title"]);

// Changes to
titleTuple.seedTextValue(getPageTitle(data));

This fixes the default page title populated for new CTA Action links

// Line 135
textField.val(data["jcr:title"]);

// Changes to
textField.val(getPageTitle(data));