File

src/converter/link-factory/fs-content-link.ts

Description

This class represents a link and allows the creation of content links.

Implements

FsLinkFactoryInterface

Index

Methods

Constructor

constructor(link: FsContentLinkTemplate, semanticPathService: SemanticPathService)
Parameters :
Name Type Optional
link FsContentLinkTemplate No
semanticPathService SemanticPathService No

Methods

Public create
create()
Returns : LinkData
Private createContentLink
createContentLink(contentPageIdentifier: string, ltTooltipText: CmsInputTextFormData)
Parameters :
Name Type Optional
contentPageIdentifier string No
ltTooltipText CmsInputTextFormData No
Returns : LinkData
Private getLinkUrl
getLinkUrl(contentPageIdentifier: string | undefined)
Parameters :
Name Type Optional
contentPageIdentifier string | undefined No
Returns : [] | undefined
import { SemanticPathService } from '@spartacus/core';
import { nullSafe } from 'fs-spartacus-common';
import { CmsInputTextFormData, LinkData } from '../teaser/fs-teaser.model';
import { FsContentLinkTemplate, FsLinkFactoryInterface } from './fs-link.model';

/**
 * This class represents a link and allows the creation of content links.
 *
 * @export
 * @class FsContentLink
 */
export class FsContentLink implements FsLinkFactoryInterface<LinkData> {
  constructor(private link: FsContentLinkTemplate, private semanticPathService: SemanticPathService) {}

  public create(): LinkData {
    if (this.link != null && this.link.formData != null) {
      const { lt_page, lt_tooltip_text } = this.link.formData;
      if (lt_page != null && lt_page.value != null && lt_page.value.uid != null) {
        return this.createContentLink(lt_page.value.uid, lt_tooltip_text);
      }
    }
    return undefined;
  }

  private createContentLink(contentPageIdentifier: string, ltTooltipText: CmsInputTextFormData): LinkData {
    return {
      href: this.getLinkUrl(contentPageIdentifier),
      tooltip: nullSafe(ltTooltipText?.value, ''),
    };
  }

  private getLinkUrl(contentPageIdentifier: string | undefined): any[] | undefined {
    if (contentPageIdentifier != null && contentPageIdentifier.length > 0) {
      return this.semanticPathService.transform(contentPageIdentifier);
    }
  }
}

results matching ""

    No results matching ""